Skip to contentSkip to conversation

pci/setup-bus: Delete an error message for a failed memory allocation in add_to_list()

PATCH Applied SF Markus Elfring 2 participants 6 messages Dec 29, 2017 – Jan 17, 2018

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pci/setup-bus: Delete an error message for a failed memory allocation in add_to_list()

From: Markus Elfring <[email protected]>
Date: Fri, 29 Dec 2017 12:15:16 +0100

Omit an extra message for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

---
 drivers/pci/setup-bus.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/pci/setup-bus.c +1 -3
index b1ad466199ad..d131d29c4fdb 100644
@@ -67,10 +67,8 @@ static int add_to_list(struct list_head *head,
 	struct pci_dev_resource *tmp;
 
 	tmp = kzalloc(sizeof(*tmp), GFP_KERNEL);
-	if (!tmp) {
-		pr_warn("add_to_list: kmalloc() failed!\n");
+	if (!tmp)
 		return -ENOMEM;
-	}
 
 	tmp->res = res;
 	tmp->dev = dev;
Signature · 1 line
2.15.1
#1 lore raw
Quoted 4 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 29 Dec 2017 12:15:16 +0100

Omit an extra message for a memory allocation failure in this function.

If this is an "extra" message, I assume there's some other message? Can you mention where that is in the changelog?

Also, please squash all the drivers/pci patches into one.

Quoted 26 lines

This issue was detected by using the Coccinelle software.

---
 drivers/pci/setup-bus.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/pci/setup-bus.c +1 -3
index b1ad466199ad..d131d29c4fdb 100644
@@ -67,10 +67,8 @@ static int add_to_list(struct list_head *head,
 	struct pci_dev_resource *tmp;
 
 	tmp = kzalloc(sizeof(*tmp), GFP_KERNEL);
-	if (!tmp) {
-		pr_warn("add_to_list: kmalloc() failed!\n");
+	if (!tmp)
 		return -ENOMEM;
-	}
 
 	tmp->res = res;
 	tmp->dev = dev;
Signature · 1 line
2.15.1
#2 lore raw
Quoted 4 lines
Quoted 1 line

Omit an extra message for a memory allocation failure in this function.

If this is an "extra" message, I assume there's some other message? Can you mention where that is in the changelog?

* Would you like to get a more detailed commit description?

* Are you looking for a reminder on the Linux allocation failure report?

Quoted 1 line

Also, please squash all the drivers/pci patches into one.

To which other change possibilities do you refer here?

Regards,
Markus

#3 lore raw
Quoted 6 lines · SF Markus Elfring
Quoted 4 lines
Quoted 1 line

Omit an extra message for a memory allocation failure in this function.

If this is an "extra" message, I assume there's some other message? Can you mention where that is in the changelog?

* Would you like to get a more detailed commit description?

Your commit message says "omit an extra message", which suggests that there are currently two messages about the memory allocation failure, and that your patch removes one of them.

If that's the case, it would be nice to know where the other message is.

If your patch removes the *only* message about the memory allocation failure, that might be worth doing, but the changelog should be clear about that and say "I don't think the error message is worthwhile because the function already returns failure" or something similar.

Quoted 1 line

* Are you looking for a reminder on the Linux allocation failure report?

I don't know what the "Linux allocation failure report" is.

Quoted 3 lines
Quoted 1 line

Also, please squash all the drivers/pci patches into one.

To which other change possibilities do you refer here?

You posted two patches that remove error messages about memory allocation failures:

http://lkml.kernel.org/r/[email protected]
http://lkml.kernel.org/r/[email protected]

These are doing the same thing and could be combined into one patch.

Bjorn

#4 lore raw
Quoted 3 lines

Your commit message says "omit an extra message", which suggests that there are currently two messages about the memory allocation failure, and that your patch removes one of them.

Yes. - There is a general transformation pattern applied.

Quoted 1 line

If that's the case, it would be nice to know where the other message is.

Have you got any special experiences with backtraces?

Quoted 2 lines

If your patch removes the *only* message about the memory allocation failure, that might be worth doing,

Thanks for a bit of positive feedback.

Quoted 1 line

but the changelog should be clear about that

Do you distinguish the “log� from a commit description?

Quoted 2 lines

and say "I don't think the error message is worthwhile because the function already returns failure" or something similar.

Do you find the wording “WARNING: Possible unnecessary 'out of memory' message� (from the script “checkpatch.pl�) more reasonable?

Quoted 3 lines
Quoted 1 line

* Are you looking for a reminder on the Linux allocation failure report?

I don't know what the "Linux allocation failure report" is.

This information seems to be “hidden� in source code.

https://elixir.free-electrons.com/linux/v4.15-rc7/source/include/linux/gfp.h#L191
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/gfp.h?idÉ2a9a461dff6140c539c61e457aa97df29517d6#n213

Are you familiar with the usage of the option “__GFP_NOWARN�?

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Also, please squash all the drivers/pci patches into one.

To which other change possibilities do you refer here?

You posted two patches that remove error messages about memory allocation failures:

Yes. - Also for this software area …

Quoted 1 line

http://lkml.kernel.org/r/[email protected]

Is it safer to handle adjustments for the directory “drivers/pci/hotplug� separately?

Quoted 3 lines

http://lkml.kernel.org/r/[email protected]

These are doing the same thing and could be combined into one patch.

The final committer could perform such an operation if an other patch granularity would be preferred (or if you would insist on patch squashing).
I guess that you do not need to wait on me to apply an adjusted software combination in this case.

Regards,
Markus
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw
Quoted 61 lines · SF Markus Elfring
Quoted 3 lines

Your commit message says "omit an extra message", which suggests that there are currently two messages about the memory allocation failure, and that your patch removes one of them.

Yes. - There is a general transformation pattern applied.

Quoted 1 line

If that's the case, it would be nice to know where the other message is.

Have you got any special experiences with backtraces?

Quoted 2 lines

If your patch removes the *only* message about the memory allocation failure, that might be worth doing,

Thanks for a bit of positive feedback.

Quoted 1 line

but the changelog should be clear about that

Do you distinguish the “log� from a commit description?

Quoted 2 lines

and say "I don't think the error message is worthwhile because the function already returns failure" or something similar.

Do you find the wording “WARNING: Possible unnecessary 'out of memory' message� (from the script “checkpatch.pl�) more reasonable?

Quoted 3 lines
Quoted 1 line

* Are you looking for a reminder on the Linux allocation failure report?

I don't know what the "Linux allocation failure report" is.

This information seems to be “hidden� in source code.

https://elixir.free-electrons.com/linux/v4.15-rc7/source/include/linux/gfp.h#L191
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/gfp.h?idÉ2a9a461dff6140c539c61e457aa97df29517d6#n213

Are you familiar with the usage of the option “__GFP_NOWARN�?

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Also, please squash all the drivers/pci patches into one.

To which other change possibilities do you refer here?

You posted two patches that remove error messages about memory allocation failures:

Yes. - Also for this software area …

Quoted 1 line

http://lkml.kernel.org/r/[email protected]

Is it safer to handle adjustments for the directory “drivers/pci/hotplug� separately?

Quoted 8 lines
Quoted 3 lines

http://lkml.kernel.org/r/[email protected]

These are doing the same thing and could be combined into one patch.

The final committer could perform such an operation if an other patch granularity would be preferred (or if you would insist on patch squashing).
I guess that you do not need to wait on me to apply an adjusted software combination in this case.

I applied the patch below to pci/misc for v4.16. Thanks for the pointers.

commit c7abb2352c298e8ac2ccfd843f036ae5244d6f35

Author: Markus Elfring <[email protected]>
Date:   Fri Dec 29 12:15:16 2017 +0100

PCI: Remove unnecessary messages for memory allocation failures

Per ebfdc40969f2 ("checkpatch: attempt to find unnecessary 'out of memory' messages"), when a memory allocation fails, the memory subsystem emits generic "out of memory" messages (see slab_out_of_memory() for some of this logging). Therefore, additional error messages in the caller don't add much value.

Remove messages that merely report "out of memory".

This preserves some messages that report additional information, e.g., allocation failures that mean we drop hotplug events.

This issue was detected by using the Coccinelle software.

[bhelgaas: changelog, squash patches, make similar changes to acpiphp, cpqphp, ibmphp, keep warning when dropping hotplug event]

drivers/pci/hotplug/acpiphp_glue.c +1 -3
index 5db6f1839dad..96f5b986454a 100644
@@ -811,10 +811,8 @@ void acpiphp_enumerate_slots(struct pci_bus *bus)
 
 	handle = adev->handle;
 	bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
-	if (!bridge) {
-		acpi_handle_err(handle, "No memory for bridge object\n");
+	if (!bridge)
 		return;
-	}
 
 	INIT_LIST_HEAD(&bridge->slots);
 	kref_init(&bridge->ref);
drivers/pci/hotplug/cpqphp_core.c +0 -1
index 70967ac75265..d28992788eaa 100644
@@ -883,7 +883,6 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	ctrl = kzalloc(sizeof(struct controller), GFP_KERNEL);
 	if (!ctrl) {
-		err("%s : out of memory\n", __func__);
 		rc = -ENOMEM;
 		goto err_disable_device;
 	}
drivers/pci/hotplug/ibmphp_core.c +3 -10
index 73cf84645c82..4f5c0b936797 100644
@@ -603,10 +603,8 @@ int ibmphp_update_slot_info(struct slot *slot_cur)
 	u8 mode;
 
 	info = kmalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL);
-	if (!info) {
-		err("out of system memory\n");
+	if (!info)
 		return -ENOMEM;
-	}
 
 	info->power_status = SLOT_PWRGD(slot_cur->status);
 	info->attention_status = SLOT_ATTN(slot_cur->status,
@@ -734,14 +732,12 @@ static u8 bus_structure_fixup(u8 busno)
 		return 1;
 
 	bus = kmalloc(sizeof(*bus), GFP_KERNEL);
-	if (!bus) {
-		err("%s - out of memory\n", __func__);
+	if (!bus)
 		return 1;
-	}
+
 	dev = kmalloc(sizeof(*dev), GFP_KERNEL);
 	if (!dev) {
 		kfree(bus);
-		err("%s - out of memory\n", __func__);
 		return 1;
 	}
 
@@ -1101,7 +1097,6 @@ static int enable_slot(struct hotplug_slot *hs)
 	if (!slot_cur->func) {
 		/* We cannot do update_slot_info here, since no memory for
 		 * kmalloc n.e.ways, and update_slot_info allocates some */
-		err("out of system memory\n");
 		rc = -ENOMEM;
 		goto error_power;
 	}
@@ -1208,7 +1203,6 @@ int ibmphp_do_disable_slot(struct slot *slot_cur)
 		/* We need this for functions that were there on bootup */
 		slot_cur->func = kzalloc(sizeof(struct pci_func), GFP_KERNEL);
 		if (!slot_cur->func) {
-			err("out of system memory\n");
 			rc = -ENOMEM;
 			goto error;
 		}
@@ -1306,7 +1300,6 @@ static int __init ibmphp_init(void)
 
 	ibmphp_pci_bus = kmalloc(sizeof(*ibmphp_pci_bus), GFP_KERNEL);
 	if (!ibmphp_pci_bus) {
-		err("out of memory\n");
 		rc = -ENOMEM;
 		goto exit;
 	}
drivers/pci/hotplug/ibmphp_pci.c +20 -40

190 lines not on this page · raw message

drivers/pci/hotplug/ibmphp_res.c +13 -25
index aee6e41001e1..b58a7a641e0e 100644
@@ -56,10 +56,8 @@ static struct bus_node * __init alloc_error_bus(struct ebda_pci_rsrc *curr, u8 b
 	}
 
 	newbus = kzalloc(sizeof(struct bus_node), GFP_KERNEL);
-	if (!newbus) {
-		err("out of system memory\n");
+	if (!newbus)
 		return NULL;
-	}
 
 	if (flag)
 		newbus->busno = busno;
@@ -79,10 +77,9 @@ static struct resource_node * __init alloc_resources(struct ebda_pci_rsrc *curr)
 	}
 
 	rs = kzalloc(sizeof(struct resource_node), GFP_KERNEL);
-	if (!rs) {
-		err("out of system memory\n");
+	if (!rs)
 		return NULL;
-	}
+
 	rs->busno = curr->bus_num;
 	rs->devfunc = curr->dev_fun;
 	rs->start = curr->start_addr;
@@ -99,10 +96,9 @@ static int __init alloc_bus_range(struct bus_node **new_bus, struct range_node *
 
 	if (first_bus) {
 		newbus = kzalloc(sizeof(struct bus_node), GFP_KERNEL);
-		if (!newbus) {
-			err("out of system memory.\n");
+		if (!newbus)
 			return -ENOMEM;
-		}
+
 		newbus->busno = curr->bus_num;
 	} else {
 		newbus = *new_bus;
@@ -123,7 +119,6 @@ static int __init alloc_bus_range(struct bus_node **new_bus, struct range_node *
 	if (!newrange) {
 		if (first_bus)
 			kfree(newbus);
-		err("out of system memory\n");
 		return -ENOMEM;
 	}
 	newrange->start = curr->start_addr;
@@ -1707,10 +1702,9 @@ static int __init once_over(void)
 				bus_cur->firstPFMemFromMem = pfmem_cur;
 
 				mem = kzalloc(sizeof(struct resource_node), GFP_KERNEL);
-				if (!mem) {
-					err("out of system memory\n");
+				if (!mem)
 					return -ENOMEM;
-				}
+
 				mem->type = MEM;
 				mem->busno = pfmem_cur->busno;
 				mem->devfunc = pfmem_cur->devfunc;
@@ -1989,10 +1983,9 @@ static int __init update_bridge_ranges(struct bus_node **bus)
 
 						if ((start_address) && (start_address <= end_address)) {
 							range = kzalloc(sizeof(struct range_node), GFP_KERNEL);
-							if (!range) {
-								err("out of system memory\n");
+							if (!range)
 								return -ENOMEM;
-							}
+
 							range->start = start_address;
 							range->end = end_address + 0xfff;
 
@@ -2016,7 +2009,6 @@ static int __init update_bridge_ranges(struct bus_node **bus)
 								io = kzalloc(sizeof(struct resource_node), GFP_KERNEL);
 								if (!io) {
 									kfree(range);
-									err("out of system memory\n");
 									return -ENOMEM;
 								}
 								io->type = IO;
@@ -2038,10 +2030,9 @@ static int __init update_bridge_ranges(struct bus_node **bus)
 						if ((start_address) && (start_address <= end_address)) {
 
 							range = kzalloc(sizeof(struct range_node), GFP_KERNEL);
-							if (!range) {
-								err("out of system memory\n");
+							if (!range)
 								return -ENOMEM;
-							}
+
 							range->start = start_address;
 							range->end = end_address + 0xfffff;
 
@@ -2066,7 +2057,6 @@ static int __init update_bridge_ranges(struct bus_node **bus)
 								mem = kzalloc(sizeof(struct resource_node), GFP_KERNEL);
 								if (!mem) {
 									kfree(range);
-									err("out of system memory\n");
 									return -ENOMEM;
 								}
 								mem->type = MEM;
@@ -2092,10 +2082,9 @@ static int __init update_bridge_ranges(struct bus_node **bus)
 						if ((start_address) && (start_address <= end_address)) {
 
 							range = kzalloc(sizeof(struct range_node), GFP_KERNEL);
-							if (!range) {
-								err("out of system memory\n");
+							if (!range)
 								return -ENOMEM;
-							}
+
 							range->start = start_address;
 							range->end = end_address + 0xfffff;
 
@@ -2119,7 +2108,6 @@ static int __init update_bridge_ranges(struct bus_node **bus)
 								pfmem = kzalloc(sizeof(struct resource_node), GFP_KERNEL);
 								if (!pfmem) {
 									kfree(range);
-									err("out of system memory\n");
 									return -ENOMEM;
 								}
 								pfmem->type = PFMEM;
drivers/pci/hotplug/pciehp_hpc.c +2 -3
index 7bab0606f1a9..ed27635ec740 100644
@@ -838,10 +838,9 @@ struct controller *pcie_init(struct pcie_device *dev)
 	struct pci_dev *pdev = dev->port;
 
 	ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL);
-	if (!ctrl) {
-		dev_err(&dev->device, "%s: Out of memory\n", __func__);
+	if (!ctrl)
 		goto abort;
-	}
+
 	ctrl->pcie = dev;
 	pcie_capability_read_dword(pdev, PCI_EXP_SLTCAP, &slot_cap);
 
drivers/pci/hotplug/pnv_php.c +0 -3
index 74f6a17e4614..318baa507364 100644
@@ -266,7 +266,6 @@ static int pnv_php_add_devtree(struct pnv_php_slot *php_slot)
 	fdt1 = kzalloc(0x10000, GFP_KERNEL);
 	if (!fdt1) {
 		ret = -ENOMEM;
-		dev_warn(&php_slot->pdev->dev, "Cannot alloc FDT blob\n");
 		goto out;
 	}
 
@@ -280,8 +279,6 @@ static int pnv_php_add_devtree(struct pnv_php_slot *php_slot)
 	fdt = kzalloc(fdt_totalsize(fdt1), GFP_KERNEL);
 	if (!fdt) {
 		ret = -ENOMEM;
-		dev_warn(&php_slot->pdev->dev, "Cannot %d bytes memory\n",
-			 fdt_totalsize(fdt1));
 		goto free_fdt1;
 	}
 
drivers/pci/hotplug/shpchp_core.c +2 -3
index 7bfb87bd2b7e..2f2b87acf179 100644
@@ -305,10 +305,9 @@ static int shpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 		return -ENODEV;
 
 	ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL);
-	if (!ctrl) {
-		dev_err(&pdev->dev, "%s: Out of memory\n", __func__);
+	if (!ctrl)
 		goto err_out_none;
-	}
+
 	INIT_LIST_HEAD(&ctrl->slot_list);
 
 	rc = shpc_init(ctrl, pdev);
drivers/pci/setup-bus.c +1 -3
index b1ad466199ad..d131d29c4fdb 100644
@@ -67,10 +67,8 @@ static int add_to_list(struct list_head *head,
 	struct pci_dev_resource *tmp;
 
 	tmp = kzalloc(sizeof(*tmp), GFP_KERNEL);
-	if (!tmp) {
-		pr_warn("add_to_list: kmalloc() failed!\n");
+	if (!tmp)
 		return -ENOMEM;
-	}
 
 	tmp->res = res;
 	tmp->dev = dev;

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html