driver core: platform: Simplify platform_device_alloc()
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
@@ -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
Quoted 4 lines · Cezary Rojewski
There is no need to double check the 'pa' object.
Reviewed-by Dawid Osuchowski <[email protected]>Signed-off-by Cezary Rojewski <[email protected]>
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.
Quoted 12 lines · Vishal Moola (Fractile)
Quoted 4 lines · Cezary Rojewski
There is no need to double check the 'pa' object.
Reviewed-by Dawid Osuchowski <[email protected]>Signed-off-by Cezary Rojewski <[email protected]>Minor nit: The commit message could be more descriptive (i.e. something like "Check whether
platform_objectallocation 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.
Reviewed-by Vishal Moola (Fractile) <[email protected]>
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
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.