[PATCH] cmd: fix do_adc_single()
Vyacheslav Bocharov
adeep at lexina.in
Sun Jul 3 14:49:09 CEST 2022
The source code contains an error:
- argv[2] contains <channel> 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
---
cmd/adc.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
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));
--
2.30.2
More information about the U-Boot
mailing list