Skip to content
/ linux Public
forked from torvalds/linux

Commit

Permalink
Merge tag 'driver-core-6.2-rc1' of git://git.kernel.org/pub/scm/linux…
Browse files Browse the repository at this point in the history
…/kernel/git/gregkh/driver-core

Pull driver core updates from Greg KH:
 "Here is the set of driver core and kernfs changes for 6.2-rc1.

  The "big" change in here is the addition of a new macro,
  container_of_const() that will preserve the "const-ness" of a pointer
  passed into it.

  The "problem" of the current container_of() macro is that if you pass
  in a "const *", out of it can comes a non-const pointer unless you
  specifically ask for it. For many usages, we want to preserve the
  "const" attribute by using the same call. For a specific example, this
  series changes the kobj_to_dev() macro to use it, allowing it to be
  used no matter what the const value is. This prevents every subsystem
  from having to declare 2 different individual macros (i.e.
  kobj_const_to_dev() and kobj_to_dev()) and having the compiler enforce
  the const value at build time, which having 2 macros would not do
  either.

  The driver for all of this have been discussions with the Rust kernel
  developers as to how to properly mark driver core, and kobject,
  objects as being "non-mutable". The changes to the kobject and driver
  core in this pull request are the result of that, as there are lots of
  paths where kobjects and device pointers are not modified at all, so
  marking them as "const" allows the compiler to enforce this.

  So, a nice side affect of the Rust development effort has been already
  to clean up the driver core code to be more obvious about object
  rules.

  All of this has been bike-shedded in quite a lot of detail on lkml
  with different names and implementations resulting in the tiny version
  we have in here, much better than my original proposal. Lots of
  subsystem maintainers have acked the changes as well.

  Other than this change, included in here are smaller stuff like:

   - kernfs fixes and updates to handle lock contention better

   - vmlinux.lds.h fixes and updates

   - sysfs and debugfs documentation updates

   - device property updates

  All of these have been in the linux-next tree for quite a while with
  no problems"

* tag 'driver-core-6.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: (58 commits)
  device property: Fix documentation for fwnode_get_next_parent()
  firmware_loader: fix up to_fw_sysfs() to preserve const
  usb.h: take advantage of container_of_const()
  device.h: move kobj_to_dev() to use container_of_const()
  container_of: add container_of_const() that preserves const-ness of the pointer
  driver core: fix up missed drivers/s390/char/hmcdrv_dev.c class.devnode() conversion.
  driver core: fix up missed scsi/cxlflash class.devnode() conversion.
  driver core: fix up some missing class.devnode() conversions.
  driver core: make struct class.devnode() take a const *
  driver core: make struct class.dev_uevent() take a const *
  cacheinfo: Remove of_node_put() for fw_token
  device property: Add a blank line in Kconfig of tests
  device property: Rename goto label to be more precise
  device property: Move PROPERTY_ENTRY_BOOL() a bit down
  device property: Get rid of __PROPERTY_ENTRY_ARRAY_EL*SIZE*()
  kernfs: fix all kernel-doc warnings and multiple typos
  driver core: pass a const * into of_device_uevent()
  kobject: kset_uevent_ops: make name() callback take a const *
  kobject: kset_uevent_ops: make filter() callback take a const *
  kobject: make kobject_namespace take a const *
  ...
  • Loading branch information
torvalds committed Dec 16, 2022
2 parents ba54ff1 + f18caf2 commit 71a7507
Show file tree
Hide file tree
Showing 92 changed files with 499 additions and 505 deletions.
12 changes: 12 additions & 0 deletions Documentation/ABI/testing/sysfs-kernel-cpu_byteorder
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
What: /sys/kernel/cpu_byteorder
Date: February 2023
KernelVersion: 6.2
Contact: Thomas Weißschuh <[email protected]>
Description:
The endianness of the running kernel.

Access: Read

Valid values:
"little", "big"
Users: util-linux
1 change: 1 addition & 0 deletions Documentation/driver-api/driver-model/devres.rst
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ MEM
devm_kmemdup()
devm_krealloc()
devm_kstrdup()
devm_kstrdup_const()
devm_kvasprintf()
devm_kzalloc()

Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/platforms/book3s/vas-api.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct coproc_instance {
struct vas_window *txwin;
};

static char *coproc_devnode(struct device *dev, umode_t *mode)
static char *coproc_devnode(const struct device *dev, umode_t *mode)
{
return kasprintf(GFP_KERNEL, "crypto/%s", dev_name(dev));
}
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/kernel/cpu/resctrl/pseudo_lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1560,9 +1560,9 @@ static const struct file_operations pseudo_lock_dev_fops = {
.mmap = pseudo_lock_dev_mmap,
};

static char *pseudo_lock_devnode(struct device *dev, umode_t *mode)
static char *pseudo_lock_devnode(const struct device *dev, umode_t *mode)
{
struct rdtgroup *rdtgrp;
const struct rdtgroup *rdtgrp;

rdtgrp = dev_get_drvdata(dev);
if (mode)
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/cpuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static int cpuid_device_destroy(unsigned int cpu)
return 0;
}

static char *cpuid_devnode(struct device *dev, umode_t *mode)
static char *cpuid_devnode(const struct device *dev, umode_t *mode)
{
return kasprintf(GFP_KERNEL, "cpu/%u/cpuid", MINOR(dev->devt));
}
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/msr.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ static int msr_device_destroy(unsigned int cpu)
return 0;
}

static char *msr_devnode(struct device *dev, umode_t *mode)
static char *msr_devnode(const struct device *dev, umode_t *mode)
{
return kasprintf(GFP_KERNEL, "cpu/%u/msr", MINOR(dev->devt));
}
Expand Down
2 changes: 1 addition & 1 deletion block/bsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ struct bsg_device *bsg_register_queue(struct request_queue *q,
}
EXPORT_SYMBOL_GPL(bsg_register_queue);

static char *bsg_devnode(struct device *dev, umode_t *mode)
static char *bsg_devnode(const struct device *dev, umode_t *mode)
{
return kasprintf(GFP_KERNEL, "bsg/%s", dev_name(dev));
}
Expand Down
4 changes: 2 additions & 2 deletions block/genhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1189,9 +1189,9 @@ static void disk_release(struct device *dev)
iput(disk->part0->bd_inode); /* frees the disk */
}

static int block_uevent(struct device *dev, struct kobj_uevent_env *env)
static int block_uevent(const struct device *dev, struct kobj_uevent_env *env)
{
struct gendisk *disk = dev_to_disk(dev);
const struct gendisk *disk = dev_to_disk(dev);

return add_uevent_var(env, "DISKSEQ=%llu", disk->diskseq);
}
Expand Down
1 change: 0 additions & 1 deletion drivers/base/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ static inline int driver_match_device(struct device_driver *drv,
{
return drv->bus->match ? drv->bus->match(dev, drv) : 1;
}
extern bool driver_allows_async_probing(struct device_driver *drv);

extern int driver_add_groups(struct device_driver *drv,
const struct attribute_group **groups);
Expand Down
2 changes: 1 addition & 1 deletion drivers/base/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ static struct kobj_type bus_ktype = {
.release = bus_release,
};

static int bus_uevent_filter(struct kobject *kobj)
static int bus_uevent_filter(const struct kobject *kobj)
{
const struct kobj_type *ktype = get_ktype(kobj);

Expand Down
19 changes: 11 additions & 8 deletions drivers/base/cacheinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ static void cache_of_set_props(struct cacheinfo *this_leaf,

static int cache_setup_of_node(unsigned int cpu)
{
struct device_node *np;
struct device_node *np, *prev;
struct cacheinfo *this_leaf;
unsigned int index = 0;

Expand All @@ -206,19 +206,24 @@ static int cache_setup_of_node(unsigned int cpu)
return -ENOENT;
}

prev = np;

while (index < cache_leaves(cpu)) {
this_leaf = per_cpu_cacheinfo_idx(cpu, index);
if (this_leaf->level != 1)
if (this_leaf->level != 1) {
np = of_find_next_cache_node(np);
else
np = of_node_get(np);/* cpu node itself */
if (!np)
break;
of_node_put(prev);
prev = np;
if (!np)
break;
}
cache_of_set_props(this_leaf, np);
this_leaf->fw_token = np;
index++;
}

of_node_put(np);

if (index != cache_leaves(cpu)) /* not all OF nodes populated */
return -ENOENT;

Expand Down Expand Up @@ -312,8 +317,6 @@ static void cache_shared_cpu_map_remove(unsigned int cpu)
cpumask_clear_cpu(cpu, &sib_leaf->shared_cpu_map);
cpumask_clear_cpu(sibling, &this_leaf->shared_cpu_map);
}
if (of_have_populated_dt())
of_node_put(this_leaf->fw_token);
}
}

Expand Down
7 changes: 6 additions & 1 deletion drivers/base/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static void class_release(struct kobject *kobj)
kfree(cp);
}

static const struct kobj_ns_type_operations *class_child_ns_type(struct kobject *kobj)
static const struct kobj_ns_type_operations *class_child_ns_type(const struct kobject *kobj)
{
struct subsys_private *cp = to_subsys_private(kobj);
struct class *class = cp->class;
Expand Down Expand Up @@ -192,6 +192,11 @@ int __class_register(struct class *cls, struct lock_class_key *key)
}
error = class_add_groups(class_get(cls), cls->class_groups);
class_put(cls);
if (error) {
kobject_del(&cp->subsys.kobj);
kfree_const(cp->subsys.kobj.name);
kfree(cp);
}
return error;
}
EXPORT_SYMBOL_GPL(__class_register);
Expand Down
66 changes: 14 additions & 52 deletions drivers/base/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <linux/err.h>
#include <linux/fwnode.h>
#include <linux/init.h>
#include <linux/kstrtox.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/string.h>
Expand Down Expand Up @@ -1628,7 +1629,7 @@ early_param("fw_devlink", fw_devlink_setup);
static bool fw_devlink_strict;
static int __init fw_devlink_strict_setup(char *arg)
{
return strtobool(arg, &fw_devlink_strict);
return kstrtobool(arg, &fw_devlink_strict);
}
early_param("fw_devlink.strict", fw_devlink_strict_setup);

Expand Down Expand Up @@ -2280,7 +2281,7 @@ ssize_t device_store_bool(struct device *dev, struct device_attribute *attr,
{
struct dev_ext_attribute *ea = to_ext_attr(attr);

if (strtobool(buf, ea->var) < 0)
if (kstrtobool(buf, ea->var) < 0)
return -EINVAL;

return size;
Expand Down Expand Up @@ -2334,9 +2335,9 @@ static void device_release(struct kobject *kobj)
kfree(p);
}

static const void *device_namespace(struct kobject *kobj)
static const void *device_namespace(const struct kobject *kobj)
{
struct device *dev = kobj_to_dev(kobj);
const struct device *dev = kobj_to_dev(kobj);
const void *ns = NULL;

if (dev->class && dev->class->ns_type)
Expand All @@ -2345,9 +2346,9 @@ static const void *device_namespace(struct kobject *kobj)
return ns;
}

static void device_get_ownership(struct kobject *kobj, kuid_t *uid, kgid_t *gid)
static void device_get_ownership(const struct kobject *kobj, kuid_t *uid, kgid_t *gid)
{
struct device *dev = kobj_to_dev(kobj);
const struct device *dev = kobj_to_dev(kobj);

if (dev->class && dev->class->get_ownership)
dev->class->get_ownership(dev, uid, gid);
Expand All @@ -2361,12 +2362,12 @@ static struct kobj_type device_ktype = {
};


static int dev_uevent_filter(struct kobject *kobj)
static int dev_uevent_filter(const struct kobject *kobj)
{
const struct kobj_type *ktype = get_ktype(kobj);

if (ktype == &device_ktype) {
struct device *dev = kobj_to_dev(kobj);
const struct device *dev = kobj_to_dev(kobj);
if (dev->bus)
return 1;
if (dev->class)
Expand All @@ -2375,9 +2376,9 @@ static int dev_uevent_filter(struct kobject *kobj)
return 0;
}

static const char *dev_uevent_name(struct kobject *kobj)
static const char *dev_uevent_name(const struct kobject *kobj)
{
struct device *dev = kobj_to_dev(kobj);
const struct device *dev = kobj_to_dev(kobj);

if (dev->bus)
return dev->bus->name;
Expand Down Expand Up @@ -2534,7 +2535,7 @@ static ssize_t online_store(struct device *dev, struct device_attribute *attr,
bool val;
int ret;

ret = strtobool(buf, &val);
ret = kstrtobool(buf, &val);
if (ret < 0)
return ret;

Expand Down Expand Up @@ -2585,11 +2586,6 @@ union device_attr_group_devres {
const struct attribute_group **groups;
};

static int devm_attr_group_match(struct device *dev, void *res, void *data)
{
return ((union device_attr_group_devres *)res)->group == data;
}

static void devm_attr_group_remove(struct device *dev, void *res)
{
union device_attr_group_devres *devres = res;
Expand Down Expand Up @@ -2640,23 +2636,6 @@ int devm_device_add_group(struct device *dev, const struct attribute_group *grp)
}
EXPORT_SYMBOL_GPL(devm_device_add_group);

/**
* devm_device_remove_group: remove a managed group from a device
* @dev: device to remove the group from
* @grp: group to remove
*
* This function removes a group of attributes from a device. The attributes
* previously have to have been created for this group, otherwise it will fail.
*/
void devm_device_remove_group(struct device *dev,
const struct attribute_group *grp)
{
WARN_ON(devres_release(dev, devm_attr_group_remove,
devm_attr_group_match,
/* cast away const */ (void *)grp));
}
EXPORT_SYMBOL_GPL(devm_device_remove_group);

/**
* devm_device_add_groups - create a bunch of managed attribute groups
* @dev: The device to create the group for
Expand Down Expand Up @@ -2693,23 +2672,6 @@ int devm_device_add_groups(struct device *dev,
}
EXPORT_SYMBOL_GPL(devm_device_add_groups);

/**
* devm_device_remove_groups - remove a list of managed groups
*
* @dev: The device for the groups to be removed from
* @groups: NULL terminated list of groups to be removed
*
* If groups is not NULL, remove the specified groups from the device.
*/
void devm_device_remove_groups(struct device *dev,
const struct attribute_group **groups)
{
WARN_ON(devres_release(dev, devm_attr_groups_remove,
devm_attr_group_match,
/* cast away const */ (void *)groups));
}
EXPORT_SYMBOL_GPL(devm_device_remove_groups);

static int device_add_attrs(struct device *dev)
{
struct class *class = dev->class;
Expand Down Expand Up @@ -3024,9 +2986,9 @@ static void class_dir_release(struct kobject *kobj)
}

static const
struct kobj_ns_type_operations *class_dir_child_ns_type(struct kobject *kobj)
struct kobj_ns_type_operations *class_dir_child_ns_type(const struct kobject *kobj)
{
struct class_dir *dir = to_class_dir(kobj);
const struct class_dir *dir = to_class_dir(kobj);
return dir->class->ns_type;
}

Expand Down
8 changes: 6 additions & 2 deletions drivers/base/dd.c
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ static int __init save_async_options(char *buf)
}
__setup("driver_async_probe=", save_async_options);

bool driver_allows_async_probing(struct device_driver *drv)
static bool driver_allows_async_probing(struct device_driver *drv)
{
switch (drv->probe_type) {
case PROBE_PREFER_ASYNCHRONOUS:
Expand Down Expand Up @@ -1162,7 +1162,11 @@ static int __driver_attach(struct device *dev, void *data)
return 0;
} else if (ret < 0) {
dev_dbg(dev, "Bus failed to match device: %d\n", ret);
return ret;
/*
* Driver could not match with device, but may match with
* another device on the bus.
*/
return 0;
} /* ret > 0 means positive match */

if (driver_allows_async_probing(drv)) {
Expand Down
3 changes: 3 additions & 0 deletions drivers/base/devres.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ static bool check_dr_size(size_t size, size_t *tot_size)
size, tot_size)))
return false;

/* Actually allocate the full kmalloc bucket size. */
*tot_size = kmalloc_size_roundup(*tot_size);

return true;
}

Expand Down
6 changes: 3 additions & 3 deletions drivers/base/firmware_loader/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static struct attribute *firmware_class_attrs[] = {
};
ATTRIBUTE_GROUPS(firmware_class);

static int do_firmware_uevent(struct fw_sysfs *fw_sysfs, struct kobj_uevent_env *env)
static int do_firmware_uevent(const struct fw_sysfs *fw_sysfs, struct kobj_uevent_env *env)
{
if (add_uevent_var(env, "FIRMWARE=%s", fw_sysfs->fw_priv->fw_name))
return -ENOMEM;
Expand All @@ -76,9 +76,9 @@ static int do_firmware_uevent(struct fw_sysfs *fw_sysfs, struct kobj_uevent_env
return 0;
}

static int firmware_uevent(struct device *dev, struct kobj_uevent_env *env)
static int firmware_uevent(const struct device *dev, struct kobj_uevent_env *env)
{
struct fw_sysfs *fw_sysfs = to_fw_sysfs(dev);
const struct fw_sysfs *fw_sysfs = to_fw_sysfs(dev);
int err = 0;

mutex_lock(&fw_lock);
Expand Down
6 changes: 1 addition & 5 deletions drivers/base/firmware_loader/sysfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@ struct fw_sysfs {
struct firmware *fw;
void *fw_upload_priv;
};

static inline struct fw_sysfs *to_fw_sysfs(struct device *dev)
{
return container_of(dev, struct fw_sysfs, dev);
}
#define to_fw_sysfs(__dev) container_of_const(__dev, struct fw_sysfs, dev)

void __fw_load_abort(struct fw_priv *fw_priv);

Expand Down
Loading

0 comments on commit 71a7507

Please sign in to comment.