Skip to contentSkip to conversation

staging: nvec: nvec_power: use GFP_KERNEL in probe()

PATCH In review Igor Putko 2 participants 2 messages Jul 10 – Jul 12

Subsystems (3)
lore
Share & tools
lore

Igor Putko

author
#0 lore raw

PATCH 1/1 staging: nvec: nvec_power: use GFP_KERNEL in probe()

nvec_power_probe() calls devm_kzalloc() with GFP_NOWAIT, which disables direct reclaim and is meant for atomic context. probe() runs in normal process context and may sleep, so this needlessly risks a spurious -ENOMEM under memory pressure instead of just waiting for reclaim like every other probe() allocation does.

nvec.c's own tegra_nvec_probe() already uses GFP_KERNEL for the identical pattern, confirming this is an oversight, not intentional.

---
 drivers/staging/nvec/nvec_power.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/nvec/nvec_power.c +1 -1
index 2faab9fde..c514d51a9 100644
@@ -377,7 +377,7 @@ static int nvec_power_probe(struct platform_device *pdev)
 	struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
 	struct power_supply_config psy_cfg = {};
 
-	power = devm_kzalloc(&pdev->dev, sizeof(struct nvec_power), GFP_NOWAIT);
+	power = devm_kzalloc(&pdev->dev, sizeof(struct nvec_power), GFP_KERNEL);
 	if (!power)
 		return -ENOMEM;
 
Signature · 1 line
2.47.3
maintainer Acked-by on v1 1/1
#1 lore raw

Hello Igore,

Quoted 8 lines · Igor Putko

nvec_power_probe() calls devm_kzalloc() with GFP_NOWAIT, which disables direct reclaim and is meant for atomic context. probe() runs in normal process context and may sleep, so this needlessly risks a spurious -ENOMEM under memory pressure instead of just waiting for reclaim like every other probe() allocation does.

nvec.c's own tegra_nvec_probe() already uses GFP_KERNEL for the identical pattern, confirming this is an oversight, not intentional.

I also see not reason to use GFP_NOWAIT here, even if it is unlikely to cause problems in this code path, as it is used during bootup where there should be "plenty" of RAM available. But I think it is a cleaner solution to do memory allocations. So

Quoted 22 lines

---
drivers/staging/nvec/nvec_power.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/nvec/nvec_power.c +1 -1
index 2faab9fde..c514d51a9 100644
@@ -377,7 +377,7 @@ static int nvec_power_probe(struct platform_device *pdev)
 	struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
 	struct power_supply_config psy_cfg = {};
 
-	power = devm_kzalloc(&pdev->dev, sizeof(struct nvec_power), GFP_NOWAIT);
+	power = devm_kzalloc(&pdev->dev, sizeof(struct nvec_power), GFP_KERNEL);
 	if (!power)
 		return -ENOMEM;
 
Signature · 1 line
2.47.3