From c5f7548445b6adc48c9076073a6f20b8806e9a87 Mon Sep 17 00:00:00 2001 From: James Clark Date: Tue, 9 May 2023 10:49:39 +0100 Subject: [PATCH 01/15] hwmon: pmbus: Use devm_krealloc_array Now that it exists, use it instead of doing the multiplication manually. Acked-by: Guenter Roeck Reviewed-by: Jonathan Cameron Signed-off-by: James Clark Link: https://lore.kernel.org/r/20230509094942.396150-3-james.clark@arm.com Signed-off-by: Greg Kroah-Hartman --- drivers/hwmon/pmbus/pmbus_core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index 9d14954da94f..fa06325f5a7c 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -1191,9 +1191,9 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr) { if (data->num_attributes >= data->max_attributes - 1) { int new_max_attrs = data->max_attributes + PMBUS_ATTR_ALLOC_SIZE; - void *new_attrs = devm_krealloc(data->dev, data->group.attrs, - new_max_attrs * sizeof(void *), - GFP_KERNEL); + void *new_attrs = devm_krealloc_array(data->dev, data->group.attrs, + new_max_attrs, sizeof(void *), + GFP_KERNEL); if (!new_attrs) return -ENOMEM; data->group.attrs = new_attrs; From 7c054b2cbac388a86ed6a85b831c044a0325e150 Mon Sep 17 00:00:00 2001 From: James Clark Date: Tue, 9 May 2023 10:49:40 +0100 Subject: [PATCH 02/15] iio: adc: Use devm_krealloc_array Now that it exists, use it instead of doing the multiplication and checking for overflow manually. Reviewed-by: Jonathan Cameron Signed-off-by: James Clark Link: https://lore.kernel.org/r/20230509094942.396150-4-james.clark@arm.com Signed-off-by: Greg Kroah-Hartman --- drivers/iio/adc/xilinx-ams.c | 9 +++------ drivers/iio/adc/xilinx-xadc-core.c | 17 +++++++---------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/drivers/iio/adc/xilinx-ams.c b/drivers/iio/adc/xilinx-ams.c index 34cf336b3490..f0b71a1220e0 100644 --- a/drivers/iio/adc/xilinx-ams.c +++ b/drivers/iio/adc/xilinx-ams.c @@ -1263,7 +1263,7 @@ static int ams_parse_firmware(struct iio_dev *indio_dev) struct device *dev = indio_dev->dev.parent; struct fwnode_handle *child = NULL; struct fwnode_handle *fwnode = dev_fwnode(dev); - size_t ams_size, dev_size; + size_t ams_size; int ret, ch_cnt = 0, i, rising_off, falling_off; unsigned int num_channels = 0; @@ -1320,11 +1320,8 @@ static int ams_parse_firmware(struct iio_dev *indio_dev) } } - dev_size = array_size(sizeof(*dev_channels), num_channels); - if (dev_size == SIZE_MAX) - return -ENOMEM; - - dev_channels = devm_krealloc(dev, ams_channels, dev_size, GFP_KERNEL); + dev_channels = devm_krealloc_array(dev, ams_channels, num_channels, + sizeof(*dev_channels), GFP_KERNEL); if (!dev_channels) return -ENOMEM; diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c index 292f2892d223..dba73300f894 100644 --- a/drivers/iio/adc/xilinx-xadc-core.c +++ b/drivers/iio/adc/xilinx-xadc-core.c @@ -613,20 +613,17 @@ static int xadc_update_scan_mode(struct iio_dev *indio_dev, const unsigned long *mask) { struct xadc *xadc = iio_priv(indio_dev); - size_t new_size, n; + size_t n; void *data; n = bitmap_weight(mask, indio_dev->masklength); - if (check_mul_overflow(n, sizeof(*xadc->data), &new_size)) - return -ENOMEM; - - data = devm_krealloc(indio_dev->dev.parent, xadc->data, - new_size, GFP_KERNEL); + data = devm_krealloc_array(indio_dev->dev.parent, xadc->data, + n, sizeof(*xadc->data), GFP_KERNEL); if (!data) return -ENOMEM; - memset(data, 0, new_size); + memset(data, 0, n * sizeof(*xadc->data)); xadc->data = data; return 0; @@ -1281,9 +1278,9 @@ static int xadc_parse_dt(struct iio_dev *indio_dev, unsigned int *conf, int irq) } indio_dev->num_channels = num_channels; - indio_dev->channels = devm_krealloc(dev, channels, - sizeof(*channels) * num_channels, - GFP_KERNEL); + indio_dev->channels = devm_krealloc_array(dev, channels, + num_channels, sizeof(*channels), + GFP_KERNEL); /* If we can't resize the channels array, just use the original */ if (!indio_dev->channels) indio_dev->channels = channels; From 9e6aa7c22d0777da16cec0d056382c9bd181aa78 Mon Sep 17 00:00:00 2001 From: James Clark Date: Tue, 9 May 2023 10:49:41 +0100 Subject: [PATCH 03/15] serial: qcom_geni: Comment use of devm_krealloc rather than devm_krealloc_array Now that devm_krealloc_array is available, add a comment justifying not changing this occurrence to avoid any future auto fixups. Link: https://lore.kernel.org/all/20230318173402.20a4f60d@jic23-huawei/ Reviewed-by: Jonathan Cameron Signed-off-by: James Clark Link: https://lore.kernel.org/r/20230509094942.396150-5-james.clark@arm.com Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/qcom_geni_serial.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c index 8582479f0211..444c74eeab7d 100644 --- a/drivers/tty/serial/qcom_geni_serial.c +++ b/drivers/tty/serial/qcom_geni_serial.c @@ -1053,6 +1053,11 @@ static int setup_fifos(struct qcom_geni_serial_port *port) (port->tx_fifo_depth * port->tx_fifo_width) / BITS_PER_BYTE; if (port->rx_buf && (old_rx_fifo_depth != port->rx_fifo_depth) && port->rx_fifo_depth) { + /* + * Use krealloc rather than krealloc_array because rx_buf is + * accessed as 1 byte entries as well as 4 byte entries so it's + * not necessarily an array. + */ port->rx_buf = devm_krealloc(uport->dev, port->rx_buf, port->rx_fifo_depth * sizeof(u32), GFP_KERNEL); From 266bff73451afb2c98541acac41386ef4f08bb5e Mon Sep 17 00:00:00 2001 From: Ivan Orlov Date: Sun, 14 May 2023 21:23:53 +0400 Subject: [PATCH 04/15] debugfs: Correct the 'debugfs_create_str' docs The documentation of the 'debugfs_create_str' says that the function returns a pointer to a dentry created, or an ERR_PTR in case of error. Actually, this is not true: this function doesn't return anything at all. Correct the documentation correspondingly. Signed-off-by: Ivan Orlov Link: https://lore.kernel.org/r/20230514172353.52878-1-ivan.orlov0322@gmail.com Signed-off-by: Greg Kroah-Hartman --- fs/debugfs/file.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index 1f971c880dde..b7711888dd17 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c @@ -940,15 +940,6 @@ static const struct file_operations fops_str_wo = { * This function creates a file in debugfs with the given name that * contains the value of the variable @value. If the @mode variable is so * set, it can be read from, and written to. - * - * This function will return a pointer to a dentry if it succeeds. This - * pointer must be passed to the debugfs_remove() function when the file is - * to be removed (no automatic cleanup happens if your module is unloaded, - * you are responsible here.) If an error occurs, ERR_PTR(-ERROR) will be - * returned. - * - * If debugfs is not enabled in the kernel, the value ERR_PTR(-ENODEV) will - * be returned. */ void debugfs_create_str(const char *name, umode_t mode, struct dentry *parent, char **value) From 54aa5b6044f89af046bcb7a9d0ca6408c0ebdd1f Mon Sep 17 00:00:00 2001 From: Jesse Brandeburg Date: Thu, 11 May 2023 09:45:01 -0700 Subject: [PATCH 05/15] MAINTAINERS: add entry for auxiliary bus When auxiliary bus was added to the kernel the MAINTAINERS file wasn't updated with a mention of the files, contributors and reviewers. Fix that oversight by adding Dave and Ira, with GregKH as (same as current) owner. CC: Greg Kroah-Hartman Signed-off-by: Jesse Brandeburg Acked-by: Dave Ertman Acked-by: Ira Weiny Link: https://lore.kernel.org/r/20230511164501.3859674-1-jesse.brandeburg@intel.com Signed-off-by: Greg Kroah-Hartman --- MAINTAINERS | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 250518fc70ff..d2867c94a22e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3383,6 +3383,16 @@ F: include/uapi/linux/audit.h F: kernel/audit* F: lib/*audit.c +AUXILIARY BUS DRIVER +M: Greg Kroah-Hartman +R: Dave Ertman +R: Ira Weiny +S: Supported +T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git +F: Documentation/driver-api/auxiliary_bus.rst +F: drivers/base/auxiliary.c +F: include/linux/auxiliary_bus.h + AUXILIARY DISPLAY DRIVERS M: Miguel Ojeda S: Maintained From 6bea9ea6bb21ccee2aad0aa2a845499e0aa2f7f9 Mon Sep 17 00:00:00 2001 From: Vladislav Efanov Date: Wed, 17 May 2023 15:50:25 +0300 Subject: [PATCH 06/15] isa: Remove unnecessary checks The isa_dev->dev.platform_data is initialized with incoming parameter isa_driver. After it isa_dev->dev.platform_data is checked for NULL, but incoming parameter isa_driver is not NULL since it is dereferenced many times before this check. Found by Linux Verification Center (linuxtesting.org) with SVACE. Signed-off-by: Vladislav Efanov Acked-by: William Breathitt Gray Link: https://lore.kernel.org/r/20230517125025.434005-1-VEfanov@ispras.ru Signed-off-by: Greg Kroah-Hartman --- drivers/base/isa.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/base/isa.c b/drivers/base/isa.c index 55e3ee2da98f..675ad3139224 100644 --- a/drivers/base/isa.c +++ b/drivers/base/isa.c @@ -149,11 +149,8 @@ int isa_register_driver(struct isa_driver *isa_driver, unsigned int ndev) break; } - if (isa_dev->dev.platform_data) { - isa_dev->next = isa_driver->devices; - isa_driver->devices = &isa_dev->dev; - } else - device_unregister(&isa_dev->dev); + isa_dev->next = isa_driver->devices; + isa_driver->devices = &isa_dev->dev; } if (!error && !isa_driver->devices) From 30480b988f88c279752f3202a26b6fee5f586aef Mon Sep 17 00:00:00 2001 From: Muchun Song Date: Tue, 23 May 2023 10:40:17 +0800 Subject: [PATCH 07/15] kernfs: fix missing kernfs_idr_lock to remove an ID from the IDR The root->ino_idr is supposed to be protected by kernfs_idr_lock, fix it. Fixes: 488dee96bb62 ("kernfs: allow creating kernfs objects with arbitrary uid/gid") Signed-off-by: Muchun Song Acked-by: Tejun Heo Link: https://lore.kernel.org/r/20230523024017.24851-1-songmuchun@bytedance.com Signed-off-by: Greg Kroah-Hartman --- fs/kernfs/dir.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c index 45b6919903e6..5a1a4af9d3d2 100644 --- a/fs/kernfs/dir.c +++ b/fs/kernfs/dir.c @@ -655,7 +655,9 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root, return kn; err_out3: + spin_lock(&kernfs_idr_lock); idr_remove(&root->ino_idr, (u32)kernfs_ino(kn)); + spin_unlock(&kernfs_idr_lock); err_out2: kmem_cache_free(kernfs_node_cache, kn); err_out1: From cd00bc2ca42705bf141a2bf6fb5224c7ae628dbe Mon Sep 17 00:00:00 2001 From: James Seo Date: Mon, 8 May 2023 19:47:05 -0700 Subject: [PATCH 08/15] driver core: device.h: add some missing kerneldocs struct device_attribute, struct dev_ext_attribute, dev_name(), and the DEVICE_ATTR() macros lack kerneldocs, preventing them from appearing in the driver core documentation and from being cross-referenced elsewhere. Add the missing kerneldocs (except for DEVICE_ATTR_IGNORE_LOCKDEP(), which is only meaningful on debug builds with CONFIG_DEBUG_LOCK_ALLOC defined, and is aliased to DEVICE_ATTR() otherwise). Tested-by: Randy Dunlap Acked-by: Randy Dunlap Signed-off-by: James Seo Link: https://lore.kernel.org/r/20230509024702.1977991-1-james@equiv.tech Signed-off-by: Greg Kroah-Hartman --- include/linux/device.h | 111 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 1 deletion(-) diff --git a/include/linux/device.h b/include/linux/device.h index 58f4f5948edb..66c13965153d 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -96,7 +96,12 @@ struct device_type { const struct dev_pm_ops *pm; }; -/* interface for exporting device attributes */ +/** + * struct device_attribute - Interface for exporting device attributes. + * @attr: sysfs attribute definition. + * @show: Show handler. + * @store: Store handler. + */ struct device_attribute { struct attribute attr; ssize_t (*show)(struct device *dev, struct device_attribute *attr, @@ -105,6 +110,11 @@ struct device_attribute { const char *buf, size_t count); }; +/** + * struct dev_ext_attribute - Exported device attribute with extra context. + * @attr: Exported device attribute. + * @var: Pointer to context. + */ struct dev_ext_attribute { struct device_attribute attr; void *var; @@ -123,30 +133,124 @@ ssize_t device_show_bool(struct device *dev, struct device_attribute *attr, ssize_t device_store_bool(struct device *dev, struct device_attribute *attr, const char *buf, size_t count); +/** + * DEVICE_ATTR - Define a device attribute. + * @_name: Attribute name. + * @_mode: File mode. + * @_show: Show handler. Optional, but mandatory if attribute is readable. + * @_store: Store handler. Optional, but mandatory if attribute is writable. + * + * Convenience macro for defining a struct device_attribute. + * + * For example, ``DEVICE_ATTR(foo, 0644, foo_show, foo_store);`` expands to: + * + * .. code-block:: c + * + * struct device_attribute dev_attr_foo = { + * .attr = { .name = "foo", .mode = 0644 }, + * .show = foo_show, + * .store = foo_store, + * }; + */ #define DEVICE_ATTR(_name, _mode, _show, _store) \ struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store) + +/** + * DEVICE_ATTR_PREALLOC - Define a preallocated device attribute. + * @_name: Attribute name. + * @_mode: File mode. + * @_show: Show handler. Optional, but mandatory if attribute is readable. + * @_store: Store handler. Optional, but mandatory if attribute is writable. + * + * Like DEVICE_ATTR(), but ``SYSFS_PREALLOC`` is set on @_mode. + */ #define DEVICE_ATTR_PREALLOC(_name, _mode, _show, _store) \ struct device_attribute dev_attr_##_name = \ __ATTR_PREALLOC(_name, _mode, _show, _store) + +/** + * DEVICE_ATTR_RW - Define a read-write device attribute. + * @_name: Attribute name. + * + * Like DEVICE_ATTR(), but @_mode is 0644, @_show is <_name>_show, + * and @_store is <_name>_store. + */ #define DEVICE_ATTR_RW(_name) \ struct device_attribute dev_attr_##_name = __ATTR_RW(_name) + +/** + * DEVICE_ATTR_ADMIN_RW - Define an admin-only read-write device attribute. + * @_name: Attribute name. + * + * Like DEVICE_ATTR_RW(), but @_mode is 0600. + */ #define DEVICE_ATTR_ADMIN_RW(_name) \ struct device_attribute dev_attr_##_name = __ATTR_RW_MODE(_name, 0600) + +/** + * DEVICE_ATTR_RO - Define a readable device attribute. + * @_name: Attribute name. + * + * Like DEVICE_ATTR(), but @_mode is 0444 and @_show is <_name>_show. + */ #define DEVICE_ATTR_RO(_name) \ struct device_attribute dev_attr_##_name = __ATTR_RO(_name) + +/** + * DEVICE_ATTR_ADMIN_RO - Define an admin-only readable device attribute. + * @_name: Attribute name. + * + * Like DEVICE_ATTR_RO(), but @_mode is 0400. + */ #define DEVICE_ATTR_ADMIN_RO(_name) \ struct device_attribute dev_attr_##_name = __ATTR_RO_MODE(_name, 0400) + +/** + * DEVICE_ATTR_WO - Define an admin-only writable device attribute. + * @_name: Attribute name. + * + * Like DEVICE_ATTR(), but @_mode is 0200 and @_store is <_name>_store. + */ #define DEVICE_ATTR_WO(_name) \ struct device_attribute dev_attr_##_name = __ATTR_WO(_name) + +/** + * DEVICE_ULONG_ATTR - Define a device attribute backed by an unsigned long. + * @_name: Attribute name. + * @_mode: File mode. + * @_var: Identifier of unsigned long. + * + * Like DEVICE_ATTR(), but @_show and @_store are automatically provided + * such that reads and writes to the attribute from userspace affect @_var. + */ #define DEVICE_ULONG_ATTR(_name, _mode, _var) \ struct dev_ext_attribute dev_attr_##_name = \ { __ATTR(_name, _mode, device_show_ulong, device_store_ulong), &(_var) } + +/** + * DEVICE_INT_ATTR - Define a device attribute backed by an int. + * @_name: Attribute name. + * @_mode: File mode. + * @_var: Identifier of int. + * + * Like DEVICE_ULONG_ATTR(), but @_var is an int. + */ #define DEVICE_INT_ATTR(_name, _mode, _var) \ struct dev_ext_attribute dev_attr_##_name = \ { __ATTR(_name, _mode, device_show_int, device_store_int), &(_var) } + +/** + * DEVICE_BOOL_ATTR - Define a device attribute backed by a bool. + * @_name: Attribute name. + * @_mode: File mode. + * @_var: Identifier of bool. + * + * Like DEVICE_ULONG_ATTR(), but @_var is a bool. + */ #define DEVICE_BOOL_ATTR(_name, _mode, _var) \ struct dev_ext_attribute dev_attr_##_name = \ { __ATTR(_name, _mode, device_show_bool, device_store_bool), &(_var) } + #define DEVICE_ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) \ struct device_attribute dev_attr_##_name = \ __ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) @@ -711,6 +815,11 @@ static inline bool device_iommu_mapped(struct device *dev) /* Get the wakeup routines, which depend on struct device */ #include +/** + * dev_name - Return a device's name. + * @dev: Device with name to get. + * Return: The kobject name of the device, or its initial name if unavailable. + */ static inline const char *dev_name(const struct device *dev) { /* Use the init name until the kobject becomes available */ From 7810f4dc879500b413bafab18ff870a68f38329a Mon Sep 17 00:00:00 2001 From: Dave Jiang Date: Fri, 5 May 2023 14:28:55 -0700 Subject: [PATCH 09/15] base/node: Use 'property' to identify an access parameter Usage of 'attr' and 'name' in the context of a sysfs attribute definition are confusing because those read as being related to: struct attribute .name Rename 'name' to 'property' in preparation for renaming 'struct node_hmem_attr' to a more generic name that can be used in more contexts ('struct access_coordinate'), and not be confused with 'struct attribute'. Suggested-by: Dan Williams Reviewed-by: Dan Williams Signed-off-by: Dave Jiang Link: https://lore.kernel.org/r/168332213518.2189163.18377767521423011290.stgit@djiang5-mobl3 Signed-off-by: Greg Kroah-Hartman --- drivers/base/node.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/base/node.c b/drivers/base/node.c index b46db17124f3..2cada01c70da 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -162,15 +162,15 @@ free: } #ifdef CONFIG_HMEM_REPORTING -#define ACCESS_ATTR(name) \ -static ssize_t name##_show(struct device *dev, \ +#define ACCESS_ATTR(property) \ +static ssize_t property##_show(struct device *dev, \ struct device_attribute *attr, \ char *buf) \ { \ return sysfs_emit(buf, "%u\n", \ - to_access_nodes(dev)->hmem_attrs.name); \ + to_access_nodes(dev)->hmem_attrs.property); \ } \ -static DEVICE_ATTR_RO(name) +static DEVICE_ATTR_RO(property) ACCESS_ATTR(read_bandwidth); ACCESS_ATTR(read_latency); From 007cfa13e034a1a2973967cbbe31e70c19e2bf31 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Fri, 9 Jun 2023 18:48:58 +0300 Subject: [PATCH 10/15] ACPI: Move ACPI_DEVICE_CLASS() to mod_devicetable.h The data type of struct acpi_device_id is defined in the mod_devicetable.h. It's suboptimal to require user with the almost agnostic code to include acpi.h solely for the macro that affects the data type defined elsewhere. Taking into account the above and for the sake of consistency move ACPI_DEVICE_CLASS() to mod_devicetable.h. Note, that with CONFIG_ACPI=n the ID table will be filed with data but it does not really matter because either it won't be used, or won't be compiled in some cases (when guarded by respective ifdeffery). Signed-off-by: Andy Shevchenko Acked-by: Rafael J. Wysocki Message-ID: <20230609154900.43024-2-andriy.shevchenko@linux.intel.com> Signed-off-by: Greg Kroah-Hartman --- include/linux/acpi.h | 14 -------------- include/linux/mod_devicetable.h | 13 +++++++++++++ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 7b71dd74baeb..0d7c6ee5f0e5 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -70,19 +70,6 @@ static inline void acpi_free_fwnode_static(struct fwnode_handle *fwnode) kfree(fwnode); } -/** - * ACPI_DEVICE_CLASS - macro used to describe an ACPI device with - * the PCI-defined class-code information - * - * @_cls : the class, subclass, prog-if triple for this device - * @_msk : the class mask for this device - * - * This macro is used to create a struct acpi_device_id that matches a - * specific PCI class. The .id and .driver_data fields will be left - * initialized with the default value. - */ -#define ACPI_DEVICE_CLASS(_cls, _msk) .cls = (_cls), .cls_msk = (_msk), - static inline bool has_acpi_companion(struct device *dev) { return is_acpi_device_node(dev->fwnode); @@ -781,7 +768,6 @@ const char *acpi_get_subsystem_id(acpi_handle handle); #define ACPI_COMPANION_SET(dev, adev) do { } while (0) #define ACPI_HANDLE(dev) (NULL) #define ACPI_HANDLE_FWNODE(fwnode) (NULL) -#define ACPI_DEVICE_CLASS(_cls, _msk) .cls = (0), .cls_msk = (0), #include diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h index ccaaeda792c0..486747518aae 100644 --- a/include/linux/mod_devicetable.h +++ b/include/linux/mod_devicetable.h @@ -221,6 +221,19 @@ struct acpi_device_id { __u32 cls_msk; }; +/** + * ACPI_DEVICE_CLASS - macro used to describe an ACPI device with + * the PCI-defined class-code information + * + * @_cls : the class, subclass, prog-if triple for this device + * @_msk : the class mask for this device + * + * This macro is used to create a struct acpi_device_id that matches a + * specific PCI class. The .id and .driver_data fields will be left + * initialized with the default value. + */ +#define ACPI_DEVICE_CLASS(_cls, _msk) .cls = (_cls), .cls_msk = (_msk), + #define PNP_ID_LEN 8 #define PNP_MAX_DEVICES 8 From 2de5897b5c148a1cdf31bf4628590825d694c37d Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Fri, 9 Jun 2023 18:48:59 +0300 Subject: [PATCH 11/15] device property: Implement device_is_compatible() Some users want to use the struct device pointer to see if the device is compatible in terms of Open Firmware specifications, i.e. if it has a 'compatible' property and it matches to the given value. Provide inline helper for the users. Signed-off-by: Andy Shevchenko Reviewed-by: Serge Semin Reviewed-by: Sakari Ailus Message-ID: <20230609154900.43024-3-andriy.shevchenko@linux.intel.com> Signed-off-by: Greg Kroah-Hartman --- include/linux/property.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/linux/property.h b/include/linux/property.h index 66df1a15d518..8c3c6685a2ae 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -85,6 +85,18 @@ bool fwnode_device_is_compatible(const struct fwnode_handle *fwnode, const char return fwnode_property_match_string(fwnode, "compatible", compat) >= 0; } +/** + * device_is_compatible - match 'compatible' property of the device with a given string + * @dev: Pointer to the struct device + * @compat: The string to match 'compatible' property with + * + * Returns: true if matches, otherwise false. + */ +static inline bool device_is_compatible(const struct device *dev, const char *compat) +{ + return fwnode_device_is_compatible(dev_fwnode(dev), compat); +} + int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode, const char *prop, const char *nargs_prop, unsigned int nargs, unsigned int index, From 259b8366fdd729413a0de399e85e49154e71de57 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Fri, 9 Jun 2023 18:49:00 +0300 Subject: [PATCH 12/15] ata: ahci_platform: Make code agnostic to OF/ACPI With the help of a new device_is_compatible() make the driver code agnostic to the OF/ACPI. This makes it neater. As a side effect the header inclusions is corrected (seems mod_devicetable.h was implicitly included). Signed-off-by: Andy Shevchenko Reviewed-by: Serge Semin Reviewed-by: Sakari Ailus Message-ID: <20230609154900.43024-4-andriy.shevchenko@linux.intel.com> Signed-off-by: Greg Kroah-Hartman --- drivers/ata/ahci_platform.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c index 299ee686ac49..c18054333f7c 100644 --- a/drivers/ata/ahci_platform.c +++ b/drivers/ata/ahci_platform.c @@ -9,14 +9,14 @@ */ #include +#include #include #include #include -#include #include +#include #include #include -#include #include #include "ahci.h" @@ -56,10 +56,10 @@ static int ahci_probe(struct platform_device *pdev) if (rc) return rc; - if (of_device_is_compatible(dev->of_node, "hisilicon,hisi-ahci")) + if (device_is_compatible(dev, "hisilicon,hisi-ahci")) hpriv->flags |= AHCI_HFLAG_NO_FBS | AHCI_HFLAG_NO_NCQ; - port = acpi_device_get_match_data(dev); + port = device_get_match_data(dev); if (!port) port = &ahci_port_info; From 39d422555e43379516d4d13f5b7162a3dee6e646 Mon Sep 17 00:00:00 2001 From: Matti Vaittinen Date: Mon, 29 May 2023 09:22:33 +0300 Subject: [PATCH 13/15] drivers: fwnode: fix fwnode_irq_get[_byname]() The fwnode_irq_get() and the fwnode_irq_get_byname() return 0 upon device-tree IRQ mapping failure. This is contradicting the fwnode_irq_get_byname() function documentation and can potentially be a source of errors like: int probe(...) { ... irq = fwnode_irq_get_byname(); if (irq <= 0) return irq; ... } Here we do correctly check the return value from fwnode_irq_get_byname() but the driver probe will now return success. (There was already one such user in-tree). Change the fwnode_irq_get_byname() to work as documented and make also the fwnode_irq_get() follow same common convention returning a negative errno upon failure. Fixes: ca0acb511c21 ("device property: Add fwnode_irq_get_byname") Suggested-by: Sakari Ailus Suggested-by: Jonathan Cameron Signed-off-by: Matti Vaittinen Reviewed-by: Andy Shevchenko Reviewed-by: Jonathan Cameron Message-ID: <3e64fe592dc99e27ef9a0b247fc49fa26b6b8a58.1685340157.git.mazziesaccount@gmail.com> Signed-off-by: Greg Kroah-Hartman --- drivers/base/property.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/base/property.c b/drivers/base/property.c index f6117ec9805c..8c40abed7852 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -987,12 +987,18 @@ EXPORT_SYMBOL(fwnode_iomap); * @fwnode: Pointer to the firmware node * @index: Zero-based index of the IRQ * - * Return: Linux IRQ number on success. Other values are determined - * according to acpi_irq_get() or of_irq_get() operation. + * Return: Linux IRQ number on success. Negative errno on failure. */ int fwnode_irq_get(const struct fwnode_handle *fwnode, unsigned int index) { - return fwnode_call_int_op(fwnode, irq_get, index); + int ret; + + ret = fwnode_call_int_op(fwnode, irq_get, index); + /* We treat mapping errors as invalid case */ + if (ret == 0) + return -EINVAL; + + return ret; } EXPORT_SYMBOL(fwnode_irq_get); From 4981e0139feeadb1cdffd43a203543afe20769fa Mon Sep 17 00:00:00 2001 From: Miquel Raynal Date: Wed, 14 Jun 2023 08:30:15 +0200 Subject: [PATCH 14/15] sysfs: Improve readability by following the kernel coding style The purpose of the if/else block is to select the right sysfs directory entry to be used for the files creation. At a first look when you have the file in front of you, it really seems like the "create_files()" lines right after the block are badly indented and the "else" does not guard. In practice the code is correct but lacks curly brackets to show where the big if/else block actually ends. Add these brackets to comply with the current kernel coding style and to ease the understanding of the whole logic. Signed-off-by: Miquel Raynal Message-ID: <20230614063018.2419043-2-miquel.raynal@bootlin.com> Signed-off-by: Greg Kroah-Hartman --- fs/sysfs/group.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index eeb0e3099421..990309132c93 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c @@ -142,8 +142,10 @@ static int internal_create_group(struct kobject *kobj, int update, return PTR_ERR(kn); } } - } else + } else { kn = kobj->sd; + } + kernfs_get(kn); error = create_files(kn, kobj, uid, gid, grp, update); if (error) { From a91845b9a872039618d74104c0721376ce092638 Mon Sep 17 00:00:00 2001 From: Miquel Raynal Date: Wed, 14 Jun 2023 08:30:16 +0200 Subject: [PATCH 15/15] sysfs: Skip empty folders creation Most sysfs attributes are statically defined, the goal with this design being to be able to move all the filesystem description into read-only memory. Anyway, it may be relevant in some cases to populate attributes at run time. This leads to situation where an attribute may or may not be present depending on conditions which are not known at compile time, up to the point where no attribute at all gets added in a folder which then becomes "sometimes" empty. Problem is, providing an attribute group with a name and without .[bin_]attrs members will be loudly refused by the core, leading in most cases to a device registration failure. The simple way to support such situation right now is to dynamically allocate an empty attribute array, which is: * a (small) waste of space * a waste of time * disturbing, to say the least, as an empty sysfs folder will be created anyway. Another (even worse) possibility would be to dynamically overwrite a member of the attribute_group list, hopefully the last, which is also supposed to remain in the read-only section. In order to avoid these hackish situations, while still giving a little bit of flexibility, we might just check the validity of the .[bin_]attrs list and, if empty, just skip the attribute group creation instead of failing. This way, developers will not be tempted to workaround the core with useless allocations or strange writes on supposedly read-only structures. The content of the WARN() message is kept but turned into a debug message in order to help developers understanding why their sysfs folders might now silently fail to be created. Signed-off-by: Miquel Raynal Message-ID: <20230614063018.2419043-3-miquel.raynal@bootlin.com> Signed-off-by: Greg Kroah-Hartman --- fs/sysfs/group.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index 990309132c93..138676463336 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c @@ -118,11 +118,13 @@ static int internal_create_group(struct kobject *kobj, int update, /* Updates may happen before the object has been instantiated */ if (unlikely(update && !kobj->sd)) return -EINVAL; + if (!grp->attrs && !grp->bin_attrs) { - WARN(1, "sysfs: (bin_)attrs not set by subsystem for group: %s/%s\n", - kobj->name, grp->name ?: ""); - return -EINVAL; + pr_debug("sysfs: (bin_)attrs not set by subsystem for group: %s/%s, skipping\n", + kobj->name, grp->name ?: ""); + return 0; } + kobject_get_ownership(kobj, &uid, &gid); if (grp->name) { if (update) {