2017-07-08 00:56:33

by Gustavo A. R. Silva

[permalink] [raw]
Subject: [PATCH] auxdisplay: ht16k33: constify fb_fix_screeninfo and fb_var_screeninfo structures

These structures are only used to copy into other structures,
so declare them as const.

This issue was detected using Coccinelle and the following semantic patch:

@r disable optional_qualifier@
identifier i;
position p;
@@
static struct fb_fix_screeninfo i@p = { ... };

@ok@
identifier r.i;
expression e;
position p;
@@
e = i@p

@bad@
position p != {r.p,ok.p};
identifier r.i;
struct fb_fix_screeninfo e;
@@
e@i@p

@depends on !bad disable optional_qualifier@
identifier r.i;
@@
static
+const
struct fb_fix_screeninfo i = { ... };

The semantic patch for fb_var_screeninfo is analogous.

Signed-off-by: Gustavo A. R. Silva <[email protected]>
---
drivers/auxdisplay/ht16k33.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/auxdisplay/ht16k33.c b/drivers/auxdisplay/ht16k33.c
index fbfa5b4..a0162b5 100644
--- a/drivers/auxdisplay/ht16k33.c
+++ b/drivers/auxdisplay/ht16k33.c
@@ -82,7 +82,7 @@ struct ht16k33_priv {
struct ht16k33_fbdev fbdev;
};

-static struct fb_fix_screeninfo ht16k33_fb_fix = {
+static const struct fb_fix_screeninfo ht16k33_fb_fix = {
.id = DRIVER_NAME,
.type = FB_TYPE_PACKED_PIXELS,
.visual = FB_VISUAL_MONO10,
@@ -93,7 +93,7 @@ static struct fb_fix_screeninfo ht16k33_fb_fix = {
.accel = FB_ACCEL_NONE,
};

-static struct fb_var_screeninfo ht16k33_fb_var = {
+static const struct fb_var_screeninfo ht16k33_fb_var = {
.xres = HT16K33_MATRIX_LED_MAX_ROWS,
.yres = HT16K33_MATRIX_LED_MAX_COLS,
.xres_virtual = HT16K33_MATRIX_LED_MAX_ROWS,
--
2.5.0


2018-02-23 13:38:40

by Miguel Ojeda

[permalink] [raw]
Subject: Re: [PATCH] auxdisplay: ht16k33: constify fb_fix_screeninfo and fb_var_screeninfo structures

Hi Gustavo,

On Sat, Jul 8, 2017 at 2:56 AM, Gustavo A. R. Silva
<[email protected]> wrote:
> These structures are only used to copy into other structures,
> so declare them as const.
>
> This issue was detected using Coccinelle and the following semantic patch:
>
> @r disable optional_qualifier@
> identifier i;
> position p;
> @@
> static struct fb_fix_screeninfo i@p = { ... };
>
> @ok@
> identifier r.i;
> expression e;
> position p;
> @@
> e = i@p
>
> @bad@
> position p != {r.p,ok.p};
> identifier r.i;
> struct fb_fix_screeninfo e;
> @@
> e@i@p
>
> @depends on !bad disable optional_qualifier@
> identifier r.i;
> @@
> static
> +const
> struct fb_fix_screeninfo i = { ... };
>
> The semantic patch for fb_var_screeninfo is analogous.
>
> Signed-off-by: Gustavo A. R. Silva <[email protected]>
> ---
> drivers/auxdisplay/ht16k33.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/auxdisplay/ht16k33.c b/drivers/auxdisplay/ht16k33.c
> index fbfa5b4..a0162b5 100644
> --- a/drivers/auxdisplay/ht16k33.c
> +++ b/drivers/auxdisplay/ht16k33.c
> @@ -82,7 +82,7 @@ struct ht16k33_priv {
> struct ht16k33_fbdev fbdev;
> };
>
> -static struct fb_fix_screeninfo ht16k33_fb_fix = {
> +static const struct fb_fix_screeninfo ht16k33_fb_fix = {
> .id = DRIVER_NAME,
> .type = FB_TYPE_PACKED_PIXELS,
> .visual = FB_VISUAL_MONO10,
> @@ -93,7 +93,7 @@ static struct fb_fix_screeninfo ht16k33_fb_fix = {
> .accel = FB_ACCEL_NONE,
> };
>
> -static struct fb_var_screeninfo ht16k33_fb_var = {
> +static const struct fb_var_screeninfo ht16k33_fb_var = {
> .xres = HT16K33_MATRIX_LED_MAX_ROWS,
> .yres = HT16K33_MATRIX_LED_MAX_COLS,
> .xres_virtual = HT16K33_MATRIX_LED_MAX_ROWS,

I will pick this up for 4.17.

Thank you for the patch!
Miguel

> --
> 2.5.0
>