Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clkdev: don't fail clkdev_alloc() if over-sized

Don't fail clkdev_alloc() if the strings are over-sized. In this case,
the entry will not match during lookup, so its useless. However, since
code fails if we return NULL leading to boot failure, return a dummy
entry with the connection and device IDs set to "bad".

Leave the warning so these problems can be found, and the useless
wasteful clkdev registrations removed.

Reported-by: Ron Economos <re@w6rz.net>
Reported-by: Guenter Roeck <linux@roeck-us.net>
Fixes: 8d532528ff6a ("clkdev: report over-sized strings when creating clkdev entries")
Closes: https://lore.kernel.org/linux-clk/7eda7621-0dde-4153-89e4-172e4c095d01@roeck-us.net.
Link: https://lore.kernel.org/r/28114882-f8d7-21bf-4536-a186e8d7a22a@w6rz.net
Tested-by: Ron Economos <re@w6rz.net>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>

+9 -2
+9 -2
drivers/clk/clkdev.c
··· 204 204 pr_err("%pV:%s: %s ID is greater than %zu\n", 205 205 &vaf, con_id, failure, max_size); 206 206 va_end(ap_copy); 207 - kfree(cla); 208 - return NULL; 207 + 208 + /* 209 + * Don't fail in this case, but as the entry won't ever match just 210 + * fill it with something that also won't match. 211 + */ 212 + strscpy(cla->con_id, "bad", sizeof(cla->con_id)); 213 + strscpy(cla->dev_id, "bad", sizeof(cla->dev_id)); 214 + 215 + return &cla->cl; 209 216 } 210 217 211 218 static struct clk_lookup *