diff mbox series

[1/2] fbdev: Move two variable assignments in fb_alloc_cmap_gfp()

Message ID 341b4af7-5c6c-cbd2-6fe3-c0e4e58f3c7d@web.de (mailing list archive)
State New, archived
Headers show
Series fbdev: Adjustments for fb_alloc_cmap_gfp() | expand

Commit Message

Markus Elfring May 23, 2023, 8:15 p.m. UTC
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 23 May 2023 21:30:29 +0200

Move the assignment for the local variables “size” and “flags”
because the computed values were only used in a single if branch.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/video/fbdev/core/fbcmap.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

--
2.40.1

Comments

Helge Deller May 24, 2023, 6:10 p.m. UTC | #1
On 5/23/23 22:15, Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Tue, 23 May 2023 21:30:29 +0200
>
> Move the assignment for the local variables “size” and “flags”
> because the computed values were only used in a single if branch.

Please do not move such variables without real need.
It makes backporting (of this and maybe follow-up patches) much more
complicated and the compiler will optimize it anyway.

Thanks!
Helge


> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>   drivers/video/fbdev/core/fbcmap.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/video/fbdev/core/fbcmap.c b/drivers/video/fbdev/core/fbcmap.c
> index ff09e57f3c38..5c1075ed28ab 100644
> --- a/drivers/video/fbdev/core/fbcmap.c
> +++ b/drivers/video/fbdev/core/fbcmap.c
> @@ -91,16 +91,17 @@ static const struct fb_cmap default_16_colors = {
>
>   int fb_alloc_cmap_gfp(struct fb_cmap *cmap, int len, int transp, gfp_t flags)
>   {
> -	int size = len * sizeof(u16);
>   	int ret = -ENOMEM;
>
> -	flags |= __GFP_NOWARN;
> -
>   	if (cmap->len != len) {
> +		int size;
> +
>   		fb_dealloc_cmap(cmap);
>   		if (!len)
>   			return 0;
>
> +		size = len * sizeof(u16);
> +		flags |= __GFP_NOWARN;
>   		cmap->red = kzalloc(size, flags);
>   		if (!cmap->red)
>   			goto fail;
> --
> 2.40.1
>
Markus Elfring May 25, 2023, 5:02 a.m. UTC | #2
>> Move the assignment for the local variables “size” and “flags”
>> because the computed values were only used in a single if branch.
>
> Please do not move such variables without real need.

Is there a need to explain desirable effects better?


> It makes backporting (of this and maybe follow-up patches) much more complicated

I suggest to reconsider such development concerns a bit more.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/log/drivers/video/fbdev/core/fbcmap.c?h=v6.4-rc3


> and the compiler will optimize it anyway.

How much do expectations fit to supported and documented software optimisations?

Regards,
Markus
diff mbox series

Patch

diff --git a/drivers/video/fbdev/core/fbcmap.c b/drivers/video/fbdev/core/fbcmap.c
index ff09e57f3c38..5c1075ed28ab 100644
--- a/drivers/video/fbdev/core/fbcmap.c
+++ b/drivers/video/fbdev/core/fbcmap.c
@@ -91,16 +91,17 @@  static const struct fb_cmap default_16_colors = {

 int fb_alloc_cmap_gfp(struct fb_cmap *cmap, int len, int transp, gfp_t flags)
 {
-	int size = len * sizeof(u16);
 	int ret = -ENOMEM;

-	flags |= __GFP_NOWARN;
-
 	if (cmap->len != len) {
+		int size;
+
 		fb_dealloc_cmap(cmap);
 		if (!len)
 			return 0;

+		size = len * sizeof(u16);
+		flags |= __GFP_NOWARN;
 		cmap->red = kzalloc(size, flags);
 		if (!cmap->red)
 			goto fail;