Skip to contentSkip to conversation

checkpatch: Add devres_alloc() to allocation functions

PATCH In review [email protected] 2 participants 3 messages Aug 12 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpatch: Add devres_alloc() to allocation functions

From: bui duc phuc <[email protected]>

Add devres_alloc() to $allocFunctions so checkpatch.pl can detect unnecessary out-of-memory messages following a failed allocation.

---
 scripts/checkpatch.pl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +2 -1
index 2b7a42bbdd94..df042d31ff1f 100755
@@ -644,7 +644,8 @@ our $allocFunctions = qr{(?x:
 		kmemdup(?:_nul)?) |
 	(?:\w+)?alloc_skb(?:_ip_align)? |
 				# dev_alloc_skb/netdev_alloc_skb, et al
-	dma_alloc_coherent
+	dma_alloc_coherent |
+	devres_alloc
 )};
 
 our $signature_tags = qr{(?xi:
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 2 lines · On Wed, 2026-08-12 at 09:43 +0700, [email protected] wrote:

Add devres_alloc() to $allocFunctions so checkpatch.pl can detect unnecessary out-of-memory messages following a failed allocation.

OK, are you also updating the 2 existing instances where there is an OOM message?

-----------
drivers/thermal/thermal_hwmon.c: ptr = devres_alloc(devm_thermal_hwmon_release, sizeof(*ptr),
drivers/thermal/thermal_hwmon.c- GFP_KERNEL);
drivers/thermal/thermal_hwmon.c- if (!ptr) {
drivers/thermal/thermal_hwmon.c- dev_warn(dev, "Failed to allocate device resource data\n");
drivers/thermal/thermal_hwmon.c- return -ENOMEM;
drivers/thermal/thermal_hwmon.c- }
-----------
drivers/usb/phy/phy.c: ptr = devres_alloc(devm_usb_phy_release2, sizeof(*ptr), GFP_KERNEL); drivers/usb/phy/phy.c- if (!ptr) {
drivers/usb/phy/phy.c- dev_dbg(dev, "failed to allocate memory for devres\n");
drivers/usb/phy/phy.c- goto err0;
drivers/usb/phy/phy.c- }
-----------

What about devres_alloc_node? (there aren't any OOM messages)

scripts/checkpatch.pl

Quoted 1 line
scripts/checkpatch.pl +0 -0

[]

Quoted 10 lines
scripts/checkpatch.pl +2 -1
@@ -644,7 +644,8 @@ our $allocFunctions = qr{(?x:
 		kmemdup(?:_nul)?) |
 	(?:\w+)?alloc_skb(?:_ip_align)? |
 				# dev_alloc_skb/netdev_alloc_skb, et al
-	dma_alloc_coherent
+	dma_alloc_coherent |
+	devres_alloc
 )};
 
 our $signature_tags = qr{(?xi:
#2 lore raw

Hi Joe,

Thank you for your review.

Quoted 19 lines

OK, are you also updating the 2 existing instances where there is an OOM message?

-----------
drivers/thermal/thermal_hwmon.c: ptr = devres_alloc(devm_thermal_hwmon_release, sizeof(*ptr),
drivers/thermal/thermal_hwmon.c- GFP_KERNEL);
drivers/thermal/thermal_hwmon.c- if (!ptr) {
drivers/thermal/thermal_hwmon.c- dev_warn(dev, "Failed to allocate device resource data\n");
drivers/thermal/thermal_hwmon.c- return -ENOMEM;
drivers/thermal/thermal_hwmon.c- }
-----------
drivers/usb/phy/phy.c: ptr = devres_alloc(devm_usb_phy_release2, sizeof(*ptr), GFP_KERNEL); drivers/usb/phy/phy.c- if (!ptr) {
drivers/usb/phy/phy.c- dev_dbg(dev, "failed to allocate memory for devres\n");
drivers/usb/phy/phy.c- goto err0;
drivers/usb/phy/phy.c- }
-----------

Quoted 2 lines

What about devres_alloc_node? (there aren't any OOM messages)

I'll send a v2 patch series addressing your comments.

Best regards,
Phuc