Skip to content

Commit 4623990

Browse files
tiwaigregkh
authored andcommitted
firmware: Avoid manual device_create_file() calls
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 <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 8a7d95f commit 4623990

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

drivers/base/firmware_class.c

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,26 @@ static struct bin_attribute firmware_attr_data = {
835835
.write = firmware_data_write,
836836
};
837837

838+
static struct attribute *fw_dev_attrs[] = {
839+
&dev_attr_loading.attr,
840+
NULL
841+
};
842+
843+
static struct bin_attribute *fw_dev_bin_attrs[] = {
844+
&firmware_attr_data,
845+
NULL
846+
};
847+
848+
static const struct attribute_group fw_dev_attr_group = {
849+
.attrs = fw_dev_attrs,
850+
.bin_attrs = fw_dev_bin_attrs,
851+
};
852+
853+
static const struct attribute_group *fw_dev_attr_groups[] = {
854+
&fw_dev_attr_group,
855+
NULL
856+
};
857+
838858
static struct firmware_priv *
839859
fw_create_instance(struct firmware *firmware, const char *fw_name,
840860
struct device *device, unsigned int opt_flags)
@@ -856,6 +876,7 @@ fw_create_instance(struct firmware *firmware, const char *fw_name,
856876
dev_set_name(f_dev, "%s", fw_name);
857877
f_dev->parent = device;
858878
f_dev->class = &firmware_class;
879+
f_dev->groups = fw_dev_attr_groups;
859880
exit:
860881
return fw_priv;
861882
}
@@ -879,25 +900,10 @@ static int _request_firmware_load(struct firmware_priv *fw_priv,
879900
goto err_put_dev;
880901
}
881902

882-
retval = device_create_bin_file(f_dev, &firmware_attr_data);
883-
if (retval) {
884-
dev_err(f_dev, "%s: sysfs_create_bin_file failed\n", __func__);
885-
goto err_del_dev;
886-
}
887-
888903
mutex_lock(&fw_lock);
889904
list_add(&buf->pending_list, &pending_fw_head);
890905
mutex_unlock(&fw_lock);
891906

892-
retval = device_create_file(f_dev, &dev_attr_loading);
893-
if (retval) {
894-
mutex_lock(&fw_lock);
895-
list_del_init(&buf->pending_list);
896-
mutex_unlock(&fw_lock);
897-
dev_err(f_dev, "%s: device_create_file failed\n", __func__);
898-
goto err_del_bin_attr;
899-
}
900-
901907
if (opt_flags & FW_OPT_UEVENT) {
902908
buf->need_uevent = true;
903909
dev_set_uevent_suppress(f_dev, false);
@@ -920,10 +926,6 @@ static int _request_firmware_load(struct firmware_priv *fw_priv,
920926
else if (!buf->data)
921927
retval = -ENOMEM;
922928

923-
device_remove_file(f_dev, &dev_attr_loading);
924-
err_del_bin_attr:
925-
device_remove_bin_file(f_dev, &firmware_attr_data);
926-
err_del_dev:
927929
device_del(f_dev);
928930
err_put_dev:
929931
put_device(f_dev);

0 commit comments

Comments
 (0)