]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
driver core: bus: Return -EIO instead of 0 when show/store invalid bus attribute
authorZijun Hu <quic_zijuhu@quicinc.com>
Wed, 24 Jul 2024 13:54:48 +0000 (21:54 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 31 Jul 2024 12:54:55 +0000 (14:54 +0200)
Return -EIO instead of 0 for below erroneous bus attribute operations:
 - read a bus attribute without show().
 - write a bus attribute without store().

Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
Link: https://lore.kernel.org/r/20240724-bus_fix-v2-1-5adbafc698fb@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/bus.c

index ffea0728b8b2fba61064c6ab9fbd2e5042022912..e5073fa82b95478862aac0817116d84a6db3bb2f 100644 (file)
@@ -152,7 +152,8 @@ static ssize_t bus_attr_show(struct kobject *kobj, struct attribute *attr,
 {
        struct bus_attribute *bus_attr = to_bus_attr(attr);
        struct subsys_private *subsys_priv = to_subsys_private(kobj);
-       ssize_t ret = 0;
+       /* return -EIO for reading a bus attribute without show() */
+       ssize_t ret = -EIO;
 
        if (bus_attr->show)
                ret = bus_attr->show(subsys_priv->bus, buf);
@@ -164,7 +165,8 @@ static ssize_t bus_attr_store(struct kobject *kobj, struct attribute *attr,
 {
        struct bus_attribute *bus_attr = to_bus_attr(attr);
        struct subsys_private *subsys_priv = to_subsys_private(kobj);
-       ssize_t ret = 0;
+       /* return -EIO for writing a bus attribute without store() */
+       ssize_t ret = -EIO;
 
        if (bus_attr->store)
                ret = bus_attr->store(subsys_priv->bus, buf, count);