From daadabfbd36d57a158623fa81585a4e9aa954c53 Mon Sep 17 00:00:00 2001 From: Anupama K Patil Date: Thu, 29 Apr 2021 01:09:01 +0530 Subject: [PATCH 1/5] drivers: pnp: isapnp: proc.c: Remove unnecessary local variables In the PNP code, there are two redundant local variables that can be dropped. This also fixes a coding style issue reported by checkpatch about an assignment made under an if () statement. Reviewed-by: Jaroslav Kysela Signed-off-by: Anupama K Patil [ rjw: Subject and changelog edits ] Signed-off-by: Rafael J. Wysocki --- drivers/pnp/isapnp/proc.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/pnp/isapnp/proc.c b/drivers/pnp/isapnp/proc.c index 785a796430fa..1ae458c02656 100644 --- a/drivers/pnp/isapnp/proc.c +++ b/drivers/pnp/isapnp/proc.c @@ -57,21 +57,20 @@ static const struct proc_ops isapnp_proc_bus_proc_ops = { static int isapnp_proc_attach_device(struct pnp_dev *dev) { struct pnp_card *bus = dev->card; - struct proc_dir_entry *de, *e; char name[16]; - if (!(de = bus->procdir)) { + if (!bus->procdir) { sprintf(name, "%02x", bus->number); - de = bus->procdir = proc_mkdir(name, isapnp_proc_bus_dir); - if (!de) + bus->procdir = proc_mkdir(name, isapnp_proc_bus_dir); + if (!bus->procdir) return -ENOMEM; } sprintf(name, "%02x", dev->number); - e = dev->procent = proc_create_data(name, S_IFREG | S_IRUGO, de, + dev->procent = proc_create_data(name, S_IFREG | S_IRUGO, bus->procdir, &isapnp_proc_bus_proc_ops, dev); - if (!e) + if (!dev->procent) return -ENOMEM; - proc_set_size(e, 256); + proc_set_size(dev->procent, 256); return 0; } From b15fc7c2c88e7a97fa347446301c37272de20ed5 Mon Sep 17 00:00:00 2001 From: Heiner Kallweit Date: Wed, 12 May 2021 22:36:12 +0200 Subject: [PATCH 2/5] PNP: Remove pnp_alloc() The kernel will complain anyway if it runs out of memory, so it is not necessary to print an extra error message when that happens and kzalloc() can be called directly instead of pnp_alloc() which then becomes redundant and can be dropped. Signed-off-by: Heiner Kallweit [ rjw: Subject and changelog edits ] Signed-off-by: Rafael J. Wysocki --- drivers/pnp/base.h | 1 - drivers/pnp/card.c | 2 +- drivers/pnp/core.c | 12 ------------ drivers/pnp/interface.c | 4 ++-- 4 files changed, 3 insertions(+), 16 deletions(-) diff --git a/drivers/pnp/base.h b/drivers/pnp/base.h index cdcfa39cf167..e74a0f6a3157 100644 --- a/drivers/pnp/base.h +++ b/drivers/pnp/base.h @@ -6,7 +6,6 @@ extern struct mutex pnp_lock; extern const struct attribute_group *pnp_dev_groups[]; -void *pnp_alloc(long size); int pnp_register_protocol(struct pnp_protocol *protocol); void pnp_unregister_protocol(struct pnp_protocol *protocol); diff --git a/drivers/pnp/card.c b/drivers/pnp/card.c index c2464ee08e4a..2430c14f472d 100644 --- a/drivers/pnp/card.c +++ b/drivers/pnp/card.c @@ -80,7 +80,7 @@ static int card_probe(struct pnp_card *card, struct pnp_card_driver *drv) if (!id) return 0; - clink = pnp_alloc(sizeof(*clink)); + clink = kzalloc(sizeof(*clink), GFP_KERNEL); if (!clink) return 0; clink->card = card; diff --git a/drivers/pnp/core.c b/drivers/pnp/core.c index a50ab002e9e4..ccdfbf3978c0 100644 --- a/drivers/pnp/core.c +++ b/drivers/pnp/core.c @@ -31,18 +31,6 @@ DEFINE_MUTEX(pnp_lock); int pnp_platform_devices; EXPORT_SYMBOL(pnp_platform_devices); -void *pnp_alloc(long size) -{ - void *result; - - result = kzalloc(size, GFP_KERNEL); - if (!result) { - printk(KERN_ERR "pnp: Out of Memory\n"); - return NULL; - } - return result; -} - static void pnp_remove_protocol(struct pnp_protocol *protocol) { mutex_lock(&pnp_lock); diff --git a/drivers/pnp/interface.c b/drivers/pnp/interface.c index 602c46893e83..44efcdb87e6f 100644 --- a/drivers/pnp/interface.c +++ b/drivers/pnp/interface.c @@ -214,7 +214,7 @@ static ssize_t options_show(struct device *dmdev, struct device_attribute *attr, int ret, dep = 0, set = 0; char *indent; - buffer = pnp_alloc(sizeof(pnp_info_buffer_t)); + buffer = kzalloc(sizeof(*buffer), GFP_KERNEL); if (!buffer) return -ENOMEM; @@ -257,7 +257,7 @@ static ssize_t resources_show(struct device *dmdev, if (!dev) return -EINVAL; - buffer = pnp_alloc(sizeof(pnp_info_buffer_t)); + buffer = kzalloc(sizeof(*buffer), GFP_KERNEL); if (!buffer) return -ENOMEM; From 5bb5ceac1275cbbe757d9eecbd4b8c8a4f403c32 Mon Sep 17 00:00:00 2001 From: Heiner Kallweit Date: Wed, 12 May 2021 22:44:41 +0200 Subject: [PATCH 3/5] PNP: Switch over to dev_dbg() Debug output in dmesg log may confuse users, so restrict debug output to cases where DEBUG is defined or dynamic debug output is enabled for the respective code piece. Signed-off-by: Heiner Kallweit [ rjw: Subject and changelog edits ] Signed-off-by: Rafael J. Wysocki --- drivers/pnp/core.c | 5 ++--- drivers/pnp/resource.c | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/pnp/core.c b/drivers/pnp/core.c index ccdfbf3978c0..4df5aa6a309c 100644 --- a/drivers/pnp/core.c +++ b/drivers/pnp/core.c @@ -215,9 +215,8 @@ int pnp_add_device(struct pnp_dev *dev) for (id = dev->id; id; id = id->next) len += scnprintf(buf + len, sizeof(buf) - len, " %s", id->id); - dev_printk(KERN_DEBUG, &dev->dev, "%s device, IDs%s (%s)\n", - dev->protocol->name, buf, - dev->active ? "active" : "disabled"); + dev_dbg(&dev->dev, "%s device, IDs%s (%s)\n", dev->protocol->name, buf, + dev->active ? "active" : "disabled"); return 0; } diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c index 70d4ba95735a..2fa0f7d55259 100644 --- a/drivers/pnp/resource.c +++ b/drivers/pnp/resource.c @@ -540,7 +540,7 @@ struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq, res->start = irq; res->end = irq; - dev_printk(KERN_DEBUG, &dev->dev, "%pR\n", res); + dev_dbg(&dev->dev, "%pR\n", res); return pnp_res; } From 3935787ebd5f4117d39c6fda6d73ecfdb747349f Mon Sep 17 00:00:00 2001 From: Zhen Lei Date: Wed, 2 Jun 2021 16:15:46 +0800 Subject: [PATCH 4/5] PNP: use DEVICE_ATTR_RO macro Use DEVICE_ATTR_RO macro helper instead of plain DEVICE_ATTR, which makes the code a bit shorter and easier to read. Signed-off-by: Zhen Lei Signed-off-by: Rafael J. Wysocki --- drivers/pnp/card.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/pnp/card.c b/drivers/pnp/card.c index 2430c14f472d..d40ed8621571 100644 --- a/drivers/pnp/card.c +++ b/drivers/pnp/card.c @@ -181,8 +181,8 @@ struct pnp_card *pnp_alloc_card(struct pnp_protocol *protocol, int id, char *pnp return card; } -static ssize_t pnp_show_card_name(struct device *dmdev, - struct device_attribute *attr, char *buf) +static ssize_t name_show(struct device *dmdev, + struct device_attribute *attr, char *buf) { char *str = buf; struct pnp_card *card = to_pnp_card(dmdev); @@ -191,10 +191,10 @@ static ssize_t pnp_show_card_name(struct device *dmdev, return (str - buf); } -static DEVICE_ATTR(name, S_IRUGO, pnp_show_card_name, NULL); +static DEVICE_ATTR_RO(name); -static ssize_t pnp_show_card_ids(struct device *dmdev, - struct device_attribute *attr, char *buf) +static ssize_t card_id_show(struct device *dmdev, + struct device_attribute *attr, char *buf) { char *str = buf; struct pnp_card *card = to_pnp_card(dmdev); @@ -207,7 +207,7 @@ static ssize_t pnp_show_card_ids(struct device *dmdev, return (str - buf); } -static DEVICE_ATTR(card_id, S_IRUGO, pnp_show_card_ids, NULL); +static DEVICE_ATTR_RO(card_id); static int pnp_interface_attach_card(struct pnp_card *card) { From 17aa26c96fb240de92db90ec1bfd616f28b6dc16 Mon Sep 17 00:00:00 2001 From: Zou Wei Date: Tue, 8 Jun 2021 20:35:32 +0800 Subject: [PATCH 5/5] PNP: pnpbios: Use list_for_each_entry() instead of list_for_each() Use list_for_each_entry() instead of list_for_each() where applicable. Reported-by: Hulk Robot Signed-off-by: Zou Wei [ rjw: Subject and changelog rewrite ] Signed-off-by: Rafael J. Wysocki --- drivers/pnp/pnpbios/core.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/pnp/pnpbios/core.c b/drivers/pnp/pnpbios/core.c index 9b760e73ee8f..669ef4700c1a 100644 --- a/drivers/pnp/pnpbios/core.c +++ b/drivers/pnp/pnpbios/core.c @@ -298,14 +298,12 @@ struct pnp_protocol pnpbios_protocol = { static int __init insert_device(struct pnp_bios_node *node) { - struct list_head *pos; struct pnp_dev *dev; char id[8]; int error; /* check if the device is already added */ - list_for_each(pos, &pnpbios_protocol.devices) { - dev = list_entry(pos, struct pnp_dev, protocol_list); + list_for_each_entry(dev, &pnpbios_protocol.devices, protocol_list) { if (dev->number == node->handle) return -EEXIST; }