From: Vyacheslav Bocharov Date: Sun, 3 Jul 2022 12:49:09 +0000 (+0300) Subject: cmd: fix do_adc_single() X-Git-Url: http://git.dujemihanovic.xyz/?a=commitdiff_plain;h=6ac4774426d687b5c365c79c9187e88f6c874878;p=u-boot.git cmd: fix do_adc_single() The source code contains an error: - argv[2] contains arg, variable for env_set is in argv[3] - number of args is 4 Revert 54d24d72601321f4470c4edf31c6b29adae424a7 cmd: simplify do_adc_single() Fixes 9de612ae4ded53f742f5f99929c06d0839471ced cmd: adc: Add support for storing ADC result in env variable Reviewed-by: Simon Glass --- diff --git a/cmd/adc.c b/cmd/adc.c index 195efa8661..1c5d3e10a3 100644 --- a/cmd/adc.c +++ b/cmd/adc.c @@ -71,6 +71,7 @@ static int do_adc_info(struct cmd_tbl *cmdtp, int flag, int argc, static int do_adc_single(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { + char *varname = NULL; struct udevice *dev; unsigned int data; int ret, uV, val; @@ -78,6 +79,9 @@ static int do_adc_single(struct cmd_tbl *cmdtp, int flag, int argc, if (argc < 3) return CMD_RET_USAGE; + if (argc >= 4) + varname = argv[3]; + ret = adc_channel_single_shot(argv[1], simple_strtol(argv[2], NULL, 0), &data); if (ret) { @@ -95,7 +99,8 @@ static int do_adc_single(struct cmd_tbl *cmdtp, int flag, int argc, printf("%u\n", data); } - env_set_ulong(argv[2], val); + if (varname) + env_set_ulong(varname, val); return CMD_RET_SUCCESS; } @@ -160,5 +165,5 @@ static char adc_help_text[] = U_BOOT_CMD_WITH_SUBCMDS(adc, "ADC sub-system", adc_help_text, U_BOOT_SUBCMD_MKENT(list, 1, 1, do_adc_list), U_BOOT_SUBCMD_MKENT(info, 2, 1, do_adc_info), - U_BOOT_SUBCMD_MKENT(single, 3, 1, do_adc_single), + U_BOOT_SUBCMD_MKENT(single, 4, 1, do_adc_single), U_BOOT_SUBCMD_MKENT(scan, 3, 1, do_adc_scan));