Skip to content

Commit

Permalink
Merge tag 'driver-core-6.10-rc1' of git://git.kernel.org/pub/scm/linu…
Browse files Browse the repository at this point in the history
…x/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
  • Loading branch information
Linus Torvalds committed May 22, 2024
2 parents be81389 + 880a746 commit d90be6e
Show file tree
Hide file tree
Showing 45 changed files with 188 additions and 422 deletions.
10 changes: 0 additions & 10 deletions arch/powerpc/perf/hv-24x7.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,16 +425,6 @@ static char *memdup_to_str(char *maybe_str, int max_len, gfp_t gfp)
return kasprintf(gfp, "%.*s", max_len, maybe_str);
}

static ssize_t device_show_string(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct dev_ext_attribute *d;

d = container_of(attr, struct dev_ext_attribute, attr);

return sprintf(buf, "%s\n", (char *)d->var);
}

static ssize_t cpumask_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
Expand Down
10 changes: 1 addition & 9 deletions arch/powerpc/platforms/powernv/opal.c
Original file line number Diff line number Diff line change
Expand Up @@ -792,14 +792,6 @@ static int __init opal_sysfs_init(void)
return 0;
}

static ssize_t export_attr_read(struct file *fp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf,
loff_t off, size_t count)
{
return memory_read_from_buffer(buf, count, &off, bin_attr->private,
bin_attr->size);
}

static int opal_add_one_export(struct kobject *parent, const char *export_name,
struct device_node *np, const char *prop_name)
{
Expand All @@ -826,7 +818,7 @@ static int opal_add_one_export(struct kobject *parent, const char *export_name,
sysfs_bin_attr_init(attr);
attr->attr.name = name;
attr->attr.mode = 0400;
attr->read = export_attr_read;
attr->read = sysfs_bin_attr_simple_read;
attr->private = __va(vals[0]);
attr->size = vals[1];

Expand Down
13 changes: 3 additions & 10 deletions arch/x86/events/intel/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -5645,18 +5645,11 @@ lbr_is_visible(struct kobject *kobj, struct attribute *attr, int i)

static char pmu_name_str[30];

static ssize_t pmu_name_show(struct device *cdev,
struct device_attribute *attr,
char *buf)
{
return snprintf(buf, PAGE_SIZE, "%s\n", pmu_name_str);
}

static DEVICE_ATTR_RO(pmu_name);
static DEVICE_STRING_ATTR_RO(pmu_name, 0444, pmu_name_str);

static struct attribute *intel_pmu_caps_attrs[] = {
&dev_attr_pmu_name.attr,
NULL
&dev_attr_pmu_name.attr.attr,
NULL
};

static DEVICE_ATTR(allow_tsx_force_abort, 0644,
Expand Down
9 changes: 1 addition & 8 deletions drivers/acpi/bgrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,7 @@ BGRT_SHOW(type, image_type);
BGRT_SHOW(xoffset, image_offset_x);
BGRT_SHOW(yoffset, image_offset_y);

static ssize_t image_read(struct file *file, struct kobject *kobj,
struct bin_attribute *attr, char *buf, loff_t off, size_t count)
{
memcpy(buf, attr->private + off, count);
return count;
}

static BIN_ATTR_RO(image, 0); /* size gets filled in later */
static BIN_ATTR_SIMPLE_RO(image);

static struct attribute *bgrt_attributes[] = {
&bgrt_attr_version.attr,
Expand Down
9 changes: 6 additions & 3 deletions drivers/base/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,14 @@ extern struct kset *devices_kset;
void devices_kset_move_last(struct device *dev);

#if defined(CONFIG_MODULES) && defined(CONFIG_SYSFS)
void module_add_driver(struct module *mod, struct device_driver *drv);
int module_add_driver(struct module *mod, struct device_driver *drv);
void module_remove_driver(struct device_driver *drv);
#else
static inline void module_add_driver(struct module *mod,
struct device_driver *drv) { }
static inline int module_add_driver(struct module *mod,
struct device_driver *drv)
{
return 0;
}
static inline void module_remove_driver(struct device_driver *drv) { }
#endif

Expand Down
9 changes: 8 additions & 1 deletion drivers/base/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,12 @@ int bus_add_driver(struct device_driver *drv)
if (error)
goto out_del_list;
}
module_add_driver(drv->owner, drv);
error = module_add_driver(drv->owner, drv);
if (error) {
printk(KERN_ERR "%s: failed to create module links for %s\n",
__func__, drv->name);
goto out_detach;
}

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

return 0;

out_detach:
driver_detach(drv);
out_del_list:
klist_del(&priv->knode_bus);
out_unregister:
Expand Down
17 changes: 9 additions & 8 deletions drivers/base/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2346,8 +2346,6 @@ static void fw_devlink_link_device(struct device *dev)

/* Device links support end. */

int (*platform_notify)(struct device *dev) = NULL;
int (*platform_notify_remove)(struct device *dev) = NULL;
static struct kobject *dev_kobj;

/* /sys/dev/char */
Expand Down Expand Up @@ -2395,16 +2393,10 @@ static void device_platform_notify(struct device *dev)
acpi_device_notify(dev);

software_node_notify(dev);

if (platform_notify)
platform_notify(dev);
}

static void device_platform_notify_remove(struct device *dev)
{
if (platform_notify_remove)
platform_notify_remove(dev);

software_node_notify_remove(dev);

acpi_device_notify_remove(dev);
Expand Down Expand Up @@ -2546,6 +2538,15 @@ ssize_t device_show_bool(struct device *dev, struct device_attribute *attr,
}
EXPORT_SYMBOL_GPL(device_show_bool);

ssize_t device_show_string(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct dev_ext_attribute *ea = to_ext_attr(attr);

return sysfs_emit(buf, "%s\n", (char *)ea->var);
}
EXPORT_SYMBOL_GPL(device_show_string);

/**
* device_release - free device structure.
* @kobj: device's kobject.
Expand Down
42 changes: 31 additions & 11 deletions drivers/base/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ static void module_create_drivers_dir(struct module_kobject *mk)
mutex_unlock(&drivers_dir_mutex);
}

void module_add_driver(struct module *mod, struct device_driver *drv)
int module_add_driver(struct module *mod, struct device_driver *drv)
{
char *driver_name;
int no_warn;
struct module_kobject *mk = NULL;
int ret;

if (!drv)
return;
return 0;

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

if (!mk)
return;
return 0;

ret = sysfs_create_link(&drv->p->kobj, &mk->kobj, "module");
if (ret)
return ret;

/* Don't check return codes; these calls are idempotent */
no_warn = sysfs_create_link(&drv->p->kobj, &mk->kobj, "module");
driver_name = make_driver_name(drv);
if (driver_name) {
module_create_drivers_dir(mk);
no_warn = sysfs_create_link(mk->drivers_dir, &drv->p->kobj,
driver_name);
kfree(driver_name);
if (!driver_name) {
ret = -ENOMEM;
goto out;
}

module_create_drivers_dir(mk);
if (!mk->drivers_dir) {
ret = -EINVAL;
goto out;
}

ret = sysfs_create_link(mk->drivers_dir, &drv->p->kobj, driver_name);
if (ret)
goto out;

kfree(driver_name);

return 0;
out:
sysfs_remove_link(&drv->p->kobj, "module");
sysfs_remove_link(mk->drivers_dir, driver_name);
kfree(driver_name);

return ret;
}

void module_remove_driver(struct device_driver *drv)
Expand Down
2 changes: 1 addition & 1 deletion drivers/base/property.c
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ EXPORT_SYMBOL_GPL(fwnode_device_is_available);

/**
* device_get_child_node_count - return the number of child nodes for device
* @dev: Device to cound the child nodes for
* @dev: Device to count the child nodes for
*
* Return: the number of child nodes for a given device.
*/
Expand Down
12 changes: 2 additions & 10 deletions drivers/firmware/dmi_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -761,16 +761,8 @@ static void __init dmi_scan_machine(void)
pr_info("DMI not present or invalid.\n");
}

static ssize_t raw_table_read(struct file *file, struct kobject *kobj,
struct bin_attribute *attr, char *buf,
loff_t pos, size_t count)
{
memcpy(buf, attr->private + pos, count);
return count;
}

static BIN_ATTR(smbios_entry_point, S_IRUSR, raw_table_read, NULL, 0);
static BIN_ATTR(DMI, S_IRUSR, raw_table_read, NULL, 0);
static BIN_ATTR_SIMPLE_ADMIN_RO(smbios_entry_point);
static BIN_ATTR_SIMPLE_ADMIN_RO(DMI);

static int __init dmi_init(void)
{
Expand Down
10 changes: 1 addition & 9 deletions drivers/firmware/efi/rci2-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,7 @@ static u8 *rci2_base;
static u32 rci2_table_len;
unsigned long rci2_table_phys __ro_after_init = EFI_INVALID_TABLE_ADDR;

static ssize_t raw_table_read(struct file *file, struct kobject *kobj,
struct bin_attribute *attr, char *buf,
loff_t pos, size_t count)
{
memcpy(buf, attr->private + pos, count);
return count;
}

static BIN_ATTR(rci2, S_IRUSR, raw_table_read, NULL, 0);
static BIN_ATTR_SIMPLE_ADMIN_RO(rci2);

static u16 checksum(void)
{
Expand Down
26 changes: 6 additions & 20 deletions drivers/gpu/drm/i915/gvt/firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,7 @@ struct gvt_firmware_header {

#define dev_to_drm_minor(d) dev_get_drvdata((d))

static ssize_t
gvt_firmware_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr, char *buf,
loff_t offset, size_t count)
{
memcpy(buf, attr->private + offset, count);
return count;
}

static struct bin_attribute firmware_attr = {
.attr = {.name = "gvt_firmware", .mode = (S_IRUSR)},
.read = gvt_firmware_read,
.write = NULL,
.mmap = NULL,
};
static BIN_ATTR_SIMPLE_ADMIN_RO(gvt_firmware);

static int expose_firmware_sysfs(struct intel_gvt *gvt)
{
Expand Down Expand Up @@ -108,10 +94,10 @@ static int expose_firmware_sysfs(struct intel_gvt *gvt)
crc32_start = offsetof(struct gvt_firmware_header, version);
h->crc32 = crc32_le(0, firmware + crc32_start, size - crc32_start);

firmware_attr.size = size;
firmware_attr.private = firmware;
bin_attr_gvt_firmware.size = size;
bin_attr_gvt_firmware.private = firmware;

ret = device_create_bin_file(&pdev->dev, &firmware_attr);
ret = device_create_bin_file(&pdev->dev, &bin_attr_gvt_firmware);
if (ret) {
vfree(firmware);
return ret;
Expand All @@ -123,8 +109,8 @@ static void clean_firmware_sysfs(struct intel_gvt *gvt)
{
struct pci_dev *pdev = to_pci_dev(gvt->gt->i915->drm.dev);

device_remove_bin_file(&pdev->dev, &firmware_attr);
vfree(firmware_attr.private);
device_remove_bin_file(&pdev->dev, &bin_attr_gvt_firmware);
vfree(bin_attr_gvt_firmware.private);
}

/**
Expand Down
15 changes: 4 additions & 11 deletions drivers/hwmon/i5k_amb.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,7 @@ struct i5k_amb_data {
unsigned int num_attrs;
};

static ssize_t name_show(struct device *dev, struct device_attribute *devattr,
char *buf)
{
return sprintf(buf, "%s\n", DRVNAME);
}


static DEVICE_ATTR_RO(name);
static DEVICE_STRING_ATTR_RO(name, 0444, DRVNAME);

static struct platform_device *amb_pdev;

Expand Down Expand Up @@ -373,7 +366,7 @@ static int i5k_amb_hwmon_init(struct platform_device *pdev)
}
}

res = device_create_file(&pdev->dev, &dev_attr_name);
res = device_create_file(&pdev->dev, &dev_attr_name.attr);
if (res)
goto exit_remove;

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

exit_remove:
device_remove_file(&pdev->dev, &dev_attr_name);
device_remove_file(&pdev->dev, &dev_attr_name.attr);
for (i = 0; i < data->num_attrs; i++)
device_remove_file(&pdev->dev, &data->attrs[i].s_attr.dev_attr);
kfree(data->attrs);
Expand Down Expand Up @@ -561,7 +554,7 @@ static void i5k_amb_remove(struct platform_device *pdev)
struct i5k_amb_data *data = platform_get_drvdata(pdev);

hwmon_device_unregister(data->hwmon_dev);
device_remove_file(&pdev->dev, &dev_attr_name);
device_remove_file(&pdev->dev, &dev_attr_name.attr);
for (i = 0; i < data->num_attrs; i++)
device_remove_file(&pdev->dev, &data->attrs[i].s_attr.dev_attr);
kfree(data->attrs);
Expand Down
Loading

0 comments on commit d90be6e

Please sign in to comment.