Commit 4bd5ead8 authored by Yoshihiro Shimoda's avatar Yoshihiro Shimoda Committed by Kishon Vijay Abraham I

phy: renesas: rcar-gen3-usb2: Fix sysfs interface of "role"

Since the role_store() uses strncmp(), it's possible to refer
out-of-memory if the sysfs data size is smaller than strlen("host").
This patch fixes it by using sysfs_streq() instead of strncmp().
Reported-by: default avatarPavel Machek <pavel@denx.de>
Fixes: 9bb86777 ("phy: rcar-gen3-usb2: add sysfs for usb role swap")
Cc: <stable@vger.kernel.org> # v4.10+
Signed-off-by: default avatarYoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Reviewed-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Acked-by: default avatarPavel Machek <pavel@denx.de>
Signed-off-by: default avatarKishon Vijay Abraham I <kishon@ti.com>
parent a8a24429
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/pm_runtime.h> #include <linux/pm_runtime.h>
#include <linux/regulator/consumer.h> #include <linux/regulator/consumer.h>
#include <linux/string.h>
#include <linux/usb/of.h> #include <linux/usb/of.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
...@@ -320,9 +321,9 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr, ...@@ -320,9 +321,9 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr,
if (!ch->is_otg_channel || !rcar_gen3_is_any_rphy_initialized(ch)) if (!ch->is_otg_channel || !rcar_gen3_is_any_rphy_initialized(ch))
return -EIO; return -EIO;
if (!strncmp(buf, "host", strlen("host"))) if (sysfs_streq(buf, "host"))
new_mode = PHY_MODE_USB_HOST; new_mode = PHY_MODE_USB_HOST;
else if (!strncmp(buf, "peripheral", strlen("peripheral"))) else if (sysfs_streq(buf, "peripheral"))
new_mode = PHY_MODE_USB_DEVICE; new_mode = PHY_MODE_USB_DEVICE;
else else
return -EINVAL; return -EINVAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment