]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
firmware: Avoid manual device_create_file() calls
authorTakashi Iwai <tiwai@suse.de>
Wed, 4 Feb 2015 14:18:07 +0000 (15:18 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 25 Mar 2015 13:41:48 +0000 (14:41 +0100)
Use the static attribute groups assigned to the device instead of
manual device_create_file() & co calls.  It simplifies the code and
can avoid possible races, too.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/firmware_class.c

index 710540f5ba7e1936c5ca3c4e78dd43cbe58a4e9c..1b5bfd7cf6b656afab31100678183aa4230d842c 100644 (file)
@@ -835,6 +835,26 @@ static struct bin_attribute firmware_attr_data = {
        .write = firmware_data_write,
 };
 
+static struct attribute *fw_dev_attrs[] = {
+       &dev_attr_loading.attr,
+       NULL
+};
+
+static struct bin_attribute *fw_dev_bin_attrs[] = {
+       &firmware_attr_data,
+       NULL
+};
+
+static const struct attribute_group fw_dev_attr_group = {
+       .attrs = fw_dev_attrs,
+       .bin_attrs = fw_dev_bin_attrs,
+};
+
+static const struct attribute_group *fw_dev_attr_groups[] = {
+       &fw_dev_attr_group,
+       NULL
+};
+
 static struct firmware_priv *
 fw_create_instance(struct firmware *firmware, const char *fw_name,
                   struct device *device, unsigned int opt_flags)
@@ -856,6 +876,7 @@ fw_create_instance(struct firmware *firmware, const char *fw_name,
        dev_set_name(f_dev, "%s", fw_name);
        f_dev->parent = device;
        f_dev->class = &firmware_class;
+       f_dev->groups = fw_dev_attr_groups;
 exit:
        return fw_priv;
 }
@@ -879,25 +900,10 @@ static int _request_firmware_load(struct firmware_priv *fw_priv,
                goto err_put_dev;
        }
 
-       retval = device_create_bin_file(f_dev, &firmware_attr_data);
-       if (retval) {
-               dev_err(f_dev, "%s: sysfs_create_bin_file failed\n", __func__);
-               goto err_del_dev;
-       }
-
        mutex_lock(&fw_lock);
        list_add(&buf->pending_list, &pending_fw_head);
        mutex_unlock(&fw_lock);
 
-       retval = device_create_file(f_dev, &dev_attr_loading);
-       if (retval) {
-               mutex_lock(&fw_lock);
-               list_del_init(&buf->pending_list);
-               mutex_unlock(&fw_lock);
-               dev_err(f_dev, "%s: device_create_file failed\n", __func__);
-               goto err_del_bin_attr;
-       }
-
        if (opt_flags & FW_OPT_UEVENT) {
                buf->need_uevent = true;
                dev_set_uevent_suppress(f_dev, false);
@@ -920,10 +926,6 @@ static int _request_firmware_load(struct firmware_priv *fw_priv,
        else if (!buf->data)
                retval = -ENOMEM;
 
-       device_remove_file(f_dev, &dev_attr_loading);
-err_del_bin_attr:
-       device_remove_bin_file(f_dev, &firmware_attr_data);
-err_del_dev:
        device_del(f_dev);
 err_put_dev:
        put_device(f_dev);