cmd: clk: replace clk_lookup by uclass_get_device_by_name
The function clk_lookup can be replaced by a direct call to uclass_get_device_by_name for UCLASS_CLK. This patch removes duplicated codes by the generic DM API and avoids issue in clk_lookup because result of uclass_get_device wasn't tested; when ret < 0, dev = NULL and dev->name is invalid, the next function call strcmp(name, dev->name) causes a crash. Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com> Link: https://lore.kernel.org/r/20220131172131.2.I7bc7762eff1e31ab7ff5b34c416ee03b8fe52200@changeid
This commit is contained in:
parent
3386fb1e48
commit
afcc26140b
18
cmd/clk.c
18
cmd/clk.c
|
|
@ -99,20 +99,6 @@ static int do_clk_dump(struct cmd_tbl *cmdtp, int flag, int argc,
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CONFIG_IS_ENABLED(DM) && CONFIG_IS_ENABLED(CLK)
|
#if CONFIG_IS_ENABLED(DM) && CONFIG_IS_ENABLED(CLK)
|
||||||
struct udevice *clk_lookup(const char *name)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
struct udevice *dev;
|
|
||||||
|
|
||||||
do {
|
|
||||||
uclass_get_device(UCLASS_CLK, i++, &dev);
|
|
||||||
if (!strcmp(name, dev->name))
|
|
||||||
return dev;
|
|
||||||
} while (dev);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int do_clk_setfreq(struct cmd_tbl *cmdtp, int flag, int argc,
|
static int do_clk_setfreq(struct cmd_tbl *cmdtp, int flag, int argc,
|
||||||
char *const argv[])
|
char *const argv[])
|
||||||
{
|
{
|
||||||
|
|
@ -125,9 +111,7 @@ static int do_clk_setfreq(struct cmd_tbl *cmdtp, int flag, int argc,
|
||||||
|
|
||||||
freq = dectoul(argv[2], NULL);
|
freq = dectoul(argv[2], NULL);
|
||||||
|
|
||||||
dev = clk_lookup(argv[1]);
|
if (!uclass_get_device_by_name(UCLASS_CLK, argv[1], &dev))
|
||||||
|
|
||||||
if (dev)
|
|
||||||
clk = dev_get_clk_ptr(dev);
|
clk = dev_get_clk_ptr(dev);
|
||||||
|
|
||||||
if (!clk) {
|
if (!clk) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue