]> git.karo-electronics.de Git - linux-beck.git/commitdiff
base: core: WARN() about bogus permissions on device attributes
authorFelipe Balbi <balbi@ti.com>
Wed, 20 Feb 2013 08:31:42 +0000 (10:31 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 15 Mar 2013 16:39:15 +0000 (09:39 -0700)
Whenever a struct device_attribute is registered
with mismatched permissions - read permission without
a show routine or write permission without store
routine - we will issue a big warning so we catch
those early enough.

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/core.c

index 56536f4b0f6b9bfd6c3aa4aa603e43e75112de87..a7391a30cb294ab7fbc405b6f5b2496654626dc2 100644 (file)
@@ -563,8 +563,15 @@ int device_create_file(struct device *dev,
                       const struct device_attribute *attr)
 {
        int error = 0;
-       if (dev)
+
+       if (dev) {
+               WARN(((attr->attr.mode & S_IWUGO) && !attr->store),
+                               "Write permission without 'store'\n");
+               WARN(((attr->attr.mode & S_IRUGO) && !attr->show),
+                               "Read permission without 'show'\n");
                error = sysfs_create_file(&dev->kobj, &attr->attr);
+       }
+
        return error;
 }