Skip to content

Commit d90be6e

Browse files
committed
Merge tag 'driver-core-6.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core
Pull driver core updates from Greg KH: "Here is the small set of driver core and kernfs changes for 6.10-rc1. Nothing major here at all, just a small set of changes for some driver core apis, and minor fixups. Included in here are: - sysfs_bin_attr_simple_read() helper added and used - device_show_string() helper added and used All usages of these were acked by the various maintainers. Also in here are: - kernfs minor cleanup - removed unused functions - typo fix in documentation - pay attention to sysfs_create_link() failures in module.c finally All of these have been in linux-next for a very long time with no reported problems" * tag 'driver-core-6.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: device property: Fix a typo in the description of device_get_child_node_count() kernfs: mount: Remove unnecessary ‘NULL’ values from knparent scsi: Use device_show_string() helper for sysfs attributes platform/x86: Use device_show_string() helper for sysfs attributes perf: Use device_show_string() helper for sysfs attributes IB/qib: Use device_show_string() helper for sysfs attributes hwmon: Use device_show_string() helper for sysfs attributes driver core: Add device_show_string() helper for sysfs attributes treewide: Use sysfs_bin_attr_simple_read() helper sysfs: Add sysfs_bin_attr_simple_read() helper module: don't ignore sysfs_create_link() failures driver core: Remove unused platform_notify, platform_notify_remove
2 parents be81389 + 880a746 commit d90be6e

File tree

45 files changed

+188
-422
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+188
-422
lines changed

arch/powerpc/perf/hv-24x7.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -425,16 +425,6 @@ static char *memdup_to_str(char *maybe_str, int max_len, gfp_t gfp)
425425
return kasprintf(gfp, "%.*s", max_len, maybe_str);
426426
}
427427

428-
static ssize_t device_show_string(struct device *dev,
429-
struct device_attribute *attr, char *buf)
430-
{
431-
struct dev_ext_attribute *d;
432-
433-
d = container_of(attr, struct dev_ext_attribute, attr);
434-
435-
return sprintf(buf, "%s\n", (char *)d->var);
436-
}
437-
438428
static ssize_t cpumask_show(struct device *dev,
439429
struct device_attribute *attr, char *buf)
440430
{

arch/powerpc/platforms/powernv/opal.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -792,14 +792,6 @@ static int __init opal_sysfs_init(void)
792792
return 0;
793793
}
794794

795-
static ssize_t export_attr_read(struct file *fp, struct kobject *kobj,
796-
struct bin_attribute *bin_attr, char *buf,
797-
loff_t off, size_t count)
798-
{
799-
return memory_read_from_buffer(buf, count, &off, bin_attr->private,
800-
bin_attr->size);
801-
}
802-
803795
static int opal_add_one_export(struct kobject *parent, const char *export_name,
804796
struct device_node *np, const char *prop_name)
805797
{
@@ -826,7 +818,7 @@ static int opal_add_one_export(struct kobject *parent, const char *export_name,
826818
sysfs_bin_attr_init(attr);
827819
attr->attr.name = name;
828820
attr->attr.mode = 0400;
829-
attr->read = export_attr_read;
821+
attr->read = sysfs_bin_attr_simple_read;
830822
attr->private = __va(vals[0]);
831823
attr->size = vals[1];
832824

arch/x86/events/intel/core.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5645,18 +5645,11 @@ lbr_is_visible(struct kobject *kobj, struct attribute *attr, int i)
56455645

56465646
static char pmu_name_str[30];
56475647

5648-
static ssize_t pmu_name_show(struct device *cdev,
5649-
struct device_attribute *attr,
5650-
char *buf)
5651-
{
5652-
return snprintf(buf, PAGE_SIZE, "%s\n", pmu_name_str);
5653-
}
5654-
5655-
static DEVICE_ATTR_RO(pmu_name);
5648+
static DEVICE_STRING_ATTR_RO(pmu_name, 0444, pmu_name_str);
56565649

56575650
static struct attribute *intel_pmu_caps_attrs[] = {
5658-
&dev_attr_pmu_name.attr,
5659-
NULL
5651+
&dev_attr_pmu_name.attr.attr,
5652+
NULL
56605653
};
56615654

56625655
static DEVICE_ATTR(allow_tsx_force_abort, 0644,

drivers/acpi/bgrt.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,7 @@ BGRT_SHOW(type, image_type);
2929
BGRT_SHOW(xoffset, image_offset_x);
3030
BGRT_SHOW(yoffset, image_offset_y);
3131

32-
static ssize_t image_read(struct file *file, struct kobject *kobj,
33-
struct bin_attribute *attr, char *buf, loff_t off, size_t count)
34-
{
35-
memcpy(buf, attr->private + off, count);
36-
return count;
37-
}
38-
39-
static BIN_ATTR_RO(image, 0); /* size gets filled in later */
32+
static BIN_ATTR_SIMPLE_RO(image);
4033

4134
static struct attribute *bgrt_attributes[] = {
4235
&bgrt_attr_version.attr,

drivers/base/base.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,14 @@ extern struct kset *devices_kset;
192192
void devices_kset_move_last(struct device *dev);
193193

194194
#if defined(CONFIG_MODULES) && defined(CONFIG_SYSFS)
195-
void module_add_driver(struct module *mod, struct device_driver *drv);
195+
int module_add_driver(struct module *mod, struct device_driver *drv);
196196
void module_remove_driver(struct device_driver *drv);
197197
#else
198-
static inline void module_add_driver(struct module *mod,
199-
struct device_driver *drv) { }
198+
static inline int module_add_driver(struct module *mod,
199+
struct device_driver *drv)
200+
{
201+
return 0;
202+
}
200203
static inline void module_remove_driver(struct device_driver *drv) { }
201204
#endif
202205

drivers/base/bus.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,12 @@ int bus_add_driver(struct device_driver *drv)
674674
if (error)
675675
goto out_del_list;
676676
}
677-
module_add_driver(drv->owner, drv);
677+
error = module_add_driver(drv->owner, drv);
678+
if (error) {
679+
printk(KERN_ERR "%s: failed to create module links for %s\n",
680+
__func__, drv->name);
681+
goto out_detach;
682+
}
678683

679684
error = driver_create_file(drv, &driver_attr_uevent);
680685
if (error) {
@@ -699,6 +704,8 @@ int bus_add_driver(struct device_driver *drv)
699704

700705
return 0;
701706

707+
out_detach:
708+
driver_detach(drv);
702709
out_del_list:
703710
klist_del(&priv->knode_bus);
704711
out_unregister:

drivers/base/core.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,8 +2346,6 @@ static void fw_devlink_link_device(struct device *dev)
23462346

23472347
/* Device links support end. */
23482348

2349-
int (*platform_notify)(struct device *dev) = NULL;
2350-
int (*platform_notify_remove)(struct device *dev) = NULL;
23512349
static struct kobject *dev_kobj;
23522350

23532351
/* /sys/dev/char */
@@ -2395,16 +2393,10 @@ static void device_platform_notify(struct device *dev)
23952393
acpi_device_notify(dev);
23962394

23972395
software_node_notify(dev);
2398-
2399-
if (platform_notify)
2400-
platform_notify(dev);
24012396
}
24022397

24032398
static void device_platform_notify_remove(struct device *dev)
24042399
{
2405-
if (platform_notify_remove)
2406-
platform_notify_remove(dev);
2407-
24082400
software_node_notify_remove(dev);
24092401

24102402
acpi_device_notify_remove(dev);
@@ -2546,6 +2538,15 @@ ssize_t device_show_bool(struct device *dev, struct device_attribute *attr,
25462538
}
25472539
EXPORT_SYMBOL_GPL(device_show_bool);
25482540

2541+
ssize_t device_show_string(struct device *dev,
2542+
struct device_attribute *attr, char *buf)
2543+
{
2544+
struct dev_ext_attribute *ea = to_ext_attr(attr);
2545+
2546+
return sysfs_emit(buf, "%s\n", (char *)ea->var);
2547+
}
2548+
EXPORT_SYMBOL_GPL(device_show_string);
2549+
25492550
/**
25502551
* device_release - free device structure.
25512552
* @kobj: device's kobject.

drivers/base/module.c

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ static void module_create_drivers_dir(struct module_kobject *mk)
3030
mutex_unlock(&drivers_dir_mutex);
3131
}
3232

33-
void module_add_driver(struct module *mod, struct device_driver *drv)
33+
int module_add_driver(struct module *mod, struct device_driver *drv)
3434
{
3535
char *driver_name;
36-
int no_warn;
3736
struct module_kobject *mk = NULL;
37+
int ret;
3838

3939
if (!drv)
40-
return;
40+
return 0;
4141

4242
if (mod)
4343
mk = &mod->mkobj;
@@ -56,17 +56,37 @@ void module_add_driver(struct module *mod, struct device_driver *drv)
5656
}
5757

5858
if (!mk)
59-
return;
59+
return 0;
60+
61+
ret = sysfs_create_link(&drv->p->kobj, &mk->kobj, "module");
62+
if (ret)
63+
return ret;
6064

61-
/* Don't check return codes; these calls are idempotent */
62-
no_warn = sysfs_create_link(&drv->p->kobj, &mk->kobj, "module");
6365
driver_name = make_driver_name(drv);
64-
if (driver_name) {
65-
module_create_drivers_dir(mk);
66-
no_warn = sysfs_create_link(mk->drivers_dir, &drv->p->kobj,
67-
driver_name);
68-
kfree(driver_name);
66+
if (!driver_name) {
67+
ret = -ENOMEM;
68+
goto out;
69+
}
70+
71+
module_create_drivers_dir(mk);
72+
if (!mk->drivers_dir) {
73+
ret = -EINVAL;
74+
goto out;
6975
}
76+
77+
ret = sysfs_create_link(mk->drivers_dir, &drv->p->kobj, driver_name);
78+
if (ret)
79+
goto out;
80+
81+
kfree(driver_name);
82+
83+
return 0;
84+
out:
85+
sysfs_remove_link(&drv->p->kobj, "module");
86+
sysfs_remove_link(mk->drivers_dir, driver_name);
87+
kfree(driver_name);
88+
89+
return ret;
7090
}
7191

7292
void module_remove_driver(struct device_driver *drv)

drivers/base/property.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ EXPORT_SYMBOL_GPL(fwnode_device_is_available);
905905

906906
/**
907907
* device_get_child_node_count - return the number of child nodes for device
908-
* @dev: Device to cound the child nodes for
908+
* @dev: Device to count the child nodes for
909909
*
910910
* Return: the number of child nodes for a given device.
911911
*/

drivers/firmware/dmi_scan.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -761,16 +761,8 @@ static void __init dmi_scan_machine(void)
761761
pr_info("DMI not present or invalid.\n");
762762
}
763763

764-
static ssize_t raw_table_read(struct file *file, struct kobject *kobj,
765-
struct bin_attribute *attr, char *buf,
766-
loff_t pos, size_t count)
767-
{
768-
memcpy(buf, attr->private + pos, count);
769-
return count;
770-
}
771-
772-
static BIN_ATTR(smbios_entry_point, S_IRUSR, raw_table_read, NULL, 0);
773-
static BIN_ATTR(DMI, S_IRUSR, raw_table_read, NULL, 0);
764+
static BIN_ATTR_SIMPLE_ADMIN_RO(smbios_entry_point);
765+
static BIN_ATTR_SIMPLE_ADMIN_RO(DMI);
774766

775767
static int __init dmi_init(void)
776768
{

drivers/firmware/efi/rci2-table.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,7 @@ static u8 *rci2_base;
4040
static u32 rci2_table_len;
4141
unsigned long rci2_table_phys __ro_after_init = EFI_INVALID_TABLE_ADDR;
4242

43-
static ssize_t raw_table_read(struct file *file, struct kobject *kobj,
44-
struct bin_attribute *attr, char *buf,
45-
loff_t pos, size_t count)
46-
{
47-
memcpy(buf, attr->private + pos, count);
48-
return count;
49-
}
50-
51-
static BIN_ATTR(rci2, S_IRUSR, raw_table_read, NULL, 0);
43+
static BIN_ATTR_SIMPLE_ADMIN_RO(rci2);
5244

5345
static u16 checksum(void)
5446
{

drivers/gpu/drm/i915/gvt/firmware.c

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,7 @@ struct gvt_firmware_header {
5151

5252
#define dev_to_drm_minor(d) dev_get_drvdata((d))
5353

54-
static ssize_t
55-
gvt_firmware_read(struct file *filp, struct kobject *kobj,
56-
struct bin_attribute *attr, char *buf,
57-
loff_t offset, size_t count)
58-
{
59-
memcpy(buf, attr->private + offset, count);
60-
return count;
61-
}
62-
63-
static struct bin_attribute firmware_attr = {
64-
.attr = {.name = "gvt_firmware", .mode = (S_IRUSR)},
65-
.read = gvt_firmware_read,
66-
.write = NULL,
67-
.mmap = NULL,
68-
};
54+
static BIN_ATTR_SIMPLE_ADMIN_RO(gvt_firmware);
6955

7056
static int expose_firmware_sysfs(struct intel_gvt *gvt)
7157
{
@@ -108,10 +94,10 @@ static int expose_firmware_sysfs(struct intel_gvt *gvt)
10894
crc32_start = offsetof(struct gvt_firmware_header, version);
10995
h->crc32 = crc32_le(0, firmware + crc32_start, size - crc32_start);
11096

111-
firmware_attr.size = size;
112-
firmware_attr.private = firmware;
97+
bin_attr_gvt_firmware.size = size;
98+
bin_attr_gvt_firmware.private = firmware;
11399

114-
ret = device_create_bin_file(&pdev->dev, &firmware_attr);
100+
ret = device_create_bin_file(&pdev->dev, &bin_attr_gvt_firmware);
115101
if (ret) {
116102
vfree(firmware);
117103
return ret;
@@ -123,8 +109,8 @@ static void clean_firmware_sysfs(struct intel_gvt *gvt)
123109
{
124110
struct pci_dev *pdev = to_pci_dev(gvt->gt->i915->drm.dev);
125111

126-
device_remove_bin_file(&pdev->dev, &firmware_attr);
127-
vfree(firmware_attr.private);
112+
device_remove_bin_file(&pdev->dev, &bin_attr_gvt_firmware);
113+
vfree(bin_attr_gvt_firmware.private);
128114
}
129115

130116
/**

drivers/hwmon/i5k_amb.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,7 @@ struct i5k_amb_data {
101101
unsigned int num_attrs;
102102
};
103103

104-
static ssize_t name_show(struct device *dev, struct device_attribute *devattr,
105-
char *buf)
106-
{
107-
return sprintf(buf, "%s\n", DRVNAME);
108-
}
109-
110-
111-
static DEVICE_ATTR_RO(name);
104+
static DEVICE_STRING_ATTR_RO(name, 0444, DRVNAME);
112105

113106
static struct platform_device *amb_pdev;
114107

@@ -373,7 +366,7 @@ static int i5k_amb_hwmon_init(struct platform_device *pdev)
373366
}
374367
}
375368

376-
res = device_create_file(&pdev->dev, &dev_attr_name);
369+
res = device_create_file(&pdev->dev, &dev_attr_name.attr);
377370
if (res)
378371
goto exit_remove;
379372

@@ -386,7 +379,7 @@ static int i5k_amb_hwmon_init(struct platform_device *pdev)
386379
return res;
387380

388381
exit_remove:
389-
device_remove_file(&pdev->dev, &dev_attr_name);
382+
device_remove_file(&pdev->dev, &dev_attr_name.attr);
390383
for (i = 0; i < data->num_attrs; i++)
391384
device_remove_file(&pdev->dev, &data->attrs[i].s_attr.dev_attr);
392385
kfree(data->attrs);
@@ -561,7 +554,7 @@ static void i5k_amb_remove(struct platform_device *pdev)
561554
struct i5k_amb_data *data = platform_get_drvdata(pdev);
562555

563556
hwmon_device_unregister(data->hwmon_dev);
564-
device_remove_file(&pdev->dev, &dev_attr_name);
557+
device_remove_file(&pdev->dev, &dev_attr_name.attr);
565558
for (i = 0; i < data->num_attrs; i++)
566559
device_remove_file(&pdev->dev, &data->attrs[i].s_attr.dev_attr);
567560
kfree(data->attrs);

0 commit comments

Comments
 (0)