From: Greg Kroah-Hartman Date: Thu, 1 Sep 2022 16:37:34 +0000 (+0200) Subject: driver core: fix driver_set_override() issue with empty strings X-Git-Tag: v6.1-rc5~454^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5666a274a6d54372d6b79b1f78682a9d827e679e;p=platform%2Fkernel%2Flinux-starfive.git driver core: fix driver_set_override() issue with empty strings Python likes to send an empty string for some sysfs files, including the driver_override field. When commit 23d99baf9d72 ("PCI: Use driver_set_override() instead of open-coding") moved the PCI core to use the driver core function instead of hand-rolling their own handler, this showed up as a regression from some userspace tools, like DPDK. Fix this up by actually looking at the length of the string first instead of trusting that userspace got it correct. Fixes: 23d99baf9d72 ("PCI: Use driver_set_override() instead of open-coding") Cc: Krzysztof Kozlowski Cc: Bjorn Helgaas Cc: "Rafael J. Wysocki" Cc: Andy Shevchenko Cc: stable Reported-by: Stephen Hemminger Tested-by: Huisong Li Reviewed-by: Stephen Hemminger Reviewed-by: Krzysztof Kozlowski Link: https://lore.kernel.org/r/20220901163734.3583106-1-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 15a75af..676b627 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -63,6 +63,12 @@ int driver_set_override(struct device *dev, const char **override, if (len >= (PAGE_SIZE - 1)) return -EINVAL; + /* + * Compute the real length of the string in case userspace sends us a + * bunch of \0 characters like python likes to do. + */ + len = strlen(s); + if (!len) { /* Empty string passed - clear override */ device_lock(dev);