Skip to contentSkip to conversation

driver core: platform: Simplify platform_device_alloc()

PATCH Applied Cezary Rojewski 3 participants 4 messages Sep 25 – Sep 28 Driver core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 driver core: platform: Simplify platform_device_alloc()

There is no need to double check the 'pa' object.

---
 drivers/base/platform.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/base/platform.c +10 -9
index b45d41b018ca..461ffcddad2c 100644
@@ -620,16 +620,17 @@ struct platform_device *platform_device_alloc(const char *name, int id)
 	struct platform_object *pa;
 
 	pa = kzalloc(sizeof(*pa) + strlen(name) + 1, GFP_KERNEL);
-	if (pa) {
-		strcpy(pa->name, name);
-		pa->pdev.name = pa->name;
-		pa->pdev.id = id;
-		device_initialize(&pa->pdev.dev);
-		pa->pdev.dev.release = platform_device_release;
-		setup_pdev_dma_masks(&pa->pdev);
-	}
+	if (!pa)
+		return NULL;
 
-	return pa ? &pa->pdev : NULL;
+	strcpy(pa->name, name);
+	pa->pdev.name = pa->name;
+	pa->pdev.id = id;
+	device_initialize(&pa->pdev.dev);
+	pa->pdev.dev.release = platform_device_release;
+	setup_pdev_dma_masks(&pa->pdev);
+
+	return &pa->pdev;
 }
 EXPORT_SYMBOL_GPL(platform_device_alloc);
 
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Cezary Rojewski

There is no need to double check the 'pa' object.

Minor nit: The commit message could be more descriptive (i.e. something like "Check whether platform_object allocation failed once instead of checking for success twice"). Although I imagine compilers are smart enough to avoid double checking anyway (I haven't looked at the generated code myself).

Either way the new code is more readable, so LGTM.

#2 lore raw
Quoted 12 lines · Vishal Moola (Fractile)
Quoted 4 lines · Cezary Rojewski

There is no need to double check the 'pa' object.

Minor nit: The commit message could be more descriptive (i.e. something like "Check whether platform_object allocation failed once instead of checking for success twice"). Although I imagine compilers are smart enough to avoid double checking anyway (I haven't looked at the generated code myself).

Quoted 3 lines

Either way the new code is more readable, so LGTM.

Thank you for the review. Given the current AI era, I tend to leave very straight-forward messages in contrast.

And yes, I believe the compiler would optimize this out anyway but the readability is the key benefit here.

Kind regards,
Czarek

maintainer Applied
#3 lore raw
In reply to Cezary Rojewski
Quoted 1 line · Cezary Rojewski

[PATCH] driver core: platform: Simplify platform_device_alloc()

Applied, thanks!

Branch: driver-core-testing
Tree: git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git

[1/1] driver core: platform: Simplify platform_device_alloc()

      commit: b728c07e309f

The patch will appear in the next linux-next integration (typically within 24 hours on weekdays).

The patch is in the driver-core-testing branch and will be promoted to driver-core-next after validation.