diff mbox series

[7/9] drm/i915/gvt: Constify formats

Message ID 20211204105527.15741-8-rikard.falkeborn@gmail.com (mailing list archive)
State New, archived
Headers show
Series drm/i915/gvt: Constify static structs | expand

Commit Message

Rikard Falkeborn Dec. 4, 2021, 10:55 a.m. UTC
These are never modified, so make them const to allow the compiler to
put them in read-only memory. WHile at it, make the description const
char* since it is never modified.

Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>
---
 drivers/gpu/drm/i915/gvt/fb_decoder.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

Comments

Wang, Zhi A Dec. 10, 2021, 8:20 a.m. UTC | #1
On 12/4/2021 12:55 PM, Rikard Falkeborn wrote:
> These are never modified, so make them const to allow the compiler to
> put them in read-only memory. WHile at it, make the description const
> char* since it is never modified.
>
> Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>
> ---
>   drivers/gpu/drm/i915/gvt/fb_decoder.c | 24 ++++++++++++------------
>   1 file changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/gvt/fb_decoder.c b/drivers/gpu/drm/i915/gvt/fb_decoder.c
> index 11a8baba6822..3c8736ae8fed 100644
> --- a/drivers/gpu/drm/i915/gvt/fb_decoder.c
> +++ b/drivers/gpu/drm/i915/gvt/fb_decoder.c
> @@ -40,12 +40,12 @@
>   
>   #define PRIMARY_FORMAT_NUM	16
>   struct pixel_format {
> -	int	drm_format;	/* Pixel format in DRM definition */
> -	int	bpp;		/* Bits per pixel, 0 indicates invalid */
> -	char	*desc;		/* The description */
> +	int		drm_format;	/* Pixel format in DRM definition */
> +	int		bpp;		/* Bits per pixel, 0 indicates invalid */
> +	const char	*desc;		/* The description */
>   };
Thanks so much for this. According to the code of i915, we prefer using 
one space as seperator.
>   
> -static struct pixel_format bdw_pixel_formats[] = {
> +static const struct pixel_format bdw_pixel_formats[] = {
>   	{DRM_FORMAT_C8, 8, "8-bit Indexed"},
>   	{DRM_FORMAT_RGB565, 16, "16-bit BGRX (5:6:5 MSB-R:G:B)"},
>   	{DRM_FORMAT_XRGB8888, 32, "32-bit BGRX (8:8:8:8 MSB-X:R:G:B)"},
> @@ -58,7 +58,7 @@ static struct pixel_format bdw_pixel_formats[] = {
>   	{0, 0, NULL},
>   };
>   
> -static struct pixel_format skl_pixel_formats[] = {
> +static const struct pixel_format skl_pixel_formats[] = {
>   	{DRM_FORMAT_YUYV, 16, "16-bit packed YUYV (8:8:8:8 MSB-V:Y2:U:Y1)"},
>   	{DRM_FORMAT_UYVY, 16, "16-bit packed UYVY (8:8:8:8 MSB-Y2:V:Y1:U)"},
>   	{DRM_FORMAT_YVYU, 16, "16-bit packed YVYU (8:8:8:8 MSB-U:Y2:V:Y1)"},
> @@ -278,14 +278,14 @@ int intel_vgpu_decode_primary_plane(struct intel_vgpu *vgpu,
>   
>   #define CURSOR_FORMAT_NUM	(1 << 6)
>   struct cursor_mode_format {
> -	int	drm_format;	/* Pixel format in DRM definition */
> -	u8	bpp;		/* Bits per pixel; 0 indicates invalid */
> -	u32	width;		/* In pixel */
> -	u32	height;		/* In lines */
> -	char	*desc;		/* The description */
> +	int		drm_format;	/* Pixel format in DRM definition */
> +	u8		bpp;		/* Bits per pixel; 0 indicates invalid */
> +	u32		width;		/* In pixel */
> +	u32		height;		/* In lines */
> +	const char	*desc;		/* The description */
>   };
The same comment as above.
> -static struct cursor_mode_format cursor_pixel_formats[] = {
> +static const struct cursor_mode_format cursor_pixel_formats[] = {
>   	{DRM_FORMAT_ARGB8888, 32, 128, 128, "128x128 32bpp ARGB"},
>   	{DRM_FORMAT_ARGB8888, 32, 256, 256, "256x256 32bpp ARGB"},
>   	{DRM_FORMAT_ARGB8888, 32, 64, 64, "64x64 32bpp ARGB"},
> @@ -391,7 +391,7 @@ int intel_vgpu_decode_cursor_plane(struct intel_vgpu *vgpu,
>   
>   #define SPRITE_FORMAT_NUM	(1 << 3)
>   
> -static struct pixel_format sprite_pixel_formats[SPRITE_FORMAT_NUM] = {
> +static const struct pixel_format sprite_pixel_formats[SPRITE_FORMAT_NUM] = {
>   	[0x0] = {DRM_FORMAT_YUV422, 16, "YUV 16-bit 4:2:2 packed"},
>   	[0x1] = {DRM_FORMAT_XRGB2101010, 32, "RGB 32-bit 2:10:10:10"},
>   	[0x2] = {DRM_FORMAT_XRGB8888, 32, "RGB 32-bit 8:8:8:8"},

The rest of the patch looks good to me.
Rikard Falkeborn Dec. 12, 2021, 1:21 p.m. UTC | #2
On Fri, Dec 10, 2021 at 08:20:22AM +0000, Wang, Zhi A wrote:
> On 12/4/2021 12:55 PM, Rikard Falkeborn wrote:
> > These are never modified, so make them const to allow the compiler to
> > put them in read-only memory. WHile at it, make the description const
> > char* since it is never modified.
> >
> > Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>
> > ---
> >   drivers/gpu/drm/i915/gvt/fb_decoder.c | 24 ++++++++++++------------
> >   1 file changed, 12 insertions(+), 12 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/gvt/fb_decoder.c b/drivers/gpu/drm/i915/gvt/fb_decoder.c
> > index 11a8baba6822..3c8736ae8fed 100644
> > --- a/drivers/gpu/drm/i915/gvt/fb_decoder.c
> > +++ b/drivers/gpu/drm/i915/gvt/fb_decoder.c
> > @@ -40,12 +40,12 @@
> >   
> >   #define PRIMARY_FORMAT_NUM	16
> >   struct pixel_format {
> > -	int	drm_format;	/* Pixel format in DRM definition */
> > -	int	bpp;		/* Bits per pixel, 0 indicates invalid */
> > -	char	*desc;		/* The description */
> > +	int		drm_format;	/* Pixel format in DRM definition */
> > +	int		bpp;		/* Bits per pixel, 0 indicates invalid */
> > +	const char	*desc;		/* The description */
> >   };
> Thanks so much for this. According to the code of i915, we prefer using 
> one space as seperator.
> >   

Thanks for reviewing. Just to clarify, is this how you want it to look:

struct pixel_format {
	int drm_format;     /* Pixel format in DRM definition */
	int bpp;            /* Bits per pixel, 0 indicates invalid */
	char *desc;         /* The description */
};

Rikard
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/gvt/fb_decoder.c b/drivers/gpu/drm/i915/gvt/fb_decoder.c
index 11a8baba6822..3c8736ae8fed 100644
--- a/drivers/gpu/drm/i915/gvt/fb_decoder.c
+++ b/drivers/gpu/drm/i915/gvt/fb_decoder.c
@@ -40,12 +40,12 @@ 
 
 #define PRIMARY_FORMAT_NUM	16
 struct pixel_format {
-	int	drm_format;	/* Pixel format in DRM definition */
-	int	bpp;		/* Bits per pixel, 0 indicates invalid */
-	char	*desc;		/* The description */
+	int		drm_format;	/* Pixel format in DRM definition */
+	int		bpp;		/* Bits per pixel, 0 indicates invalid */
+	const char	*desc;		/* The description */
 };
 
-static struct pixel_format bdw_pixel_formats[] = {
+static const struct pixel_format bdw_pixel_formats[] = {
 	{DRM_FORMAT_C8, 8, "8-bit Indexed"},
 	{DRM_FORMAT_RGB565, 16, "16-bit BGRX (5:6:5 MSB-R:G:B)"},
 	{DRM_FORMAT_XRGB8888, 32, "32-bit BGRX (8:8:8:8 MSB-X:R:G:B)"},
@@ -58,7 +58,7 @@  static struct pixel_format bdw_pixel_formats[] = {
 	{0, 0, NULL},
 };
 
-static struct pixel_format skl_pixel_formats[] = {
+static const struct pixel_format skl_pixel_formats[] = {
 	{DRM_FORMAT_YUYV, 16, "16-bit packed YUYV (8:8:8:8 MSB-V:Y2:U:Y1)"},
 	{DRM_FORMAT_UYVY, 16, "16-bit packed UYVY (8:8:8:8 MSB-Y2:V:Y1:U)"},
 	{DRM_FORMAT_YVYU, 16, "16-bit packed YVYU (8:8:8:8 MSB-U:Y2:V:Y1)"},
@@ -278,14 +278,14 @@  int intel_vgpu_decode_primary_plane(struct intel_vgpu *vgpu,
 
 #define CURSOR_FORMAT_NUM	(1 << 6)
 struct cursor_mode_format {
-	int	drm_format;	/* Pixel format in DRM definition */
-	u8	bpp;		/* Bits per pixel; 0 indicates invalid */
-	u32	width;		/* In pixel */
-	u32	height;		/* In lines */
-	char	*desc;		/* The description */
+	int		drm_format;	/* Pixel format in DRM definition */
+	u8		bpp;		/* Bits per pixel; 0 indicates invalid */
+	u32		width;		/* In pixel */
+	u32		height;		/* In lines */
+	const char	*desc;		/* The description */
 };
 
-static struct cursor_mode_format cursor_pixel_formats[] = {
+static const struct cursor_mode_format cursor_pixel_formats[] = {
 	{DRM_FORMAT_ARGB8888, 32, 128, 128, "128x128 32bpp ARGB"},
 	{DRM_FORMAT_ARGB8888, 32, 256, 256, "256x256 32bpp ARGB"},
 	{DRM_FORMAT_ARGB8888, 32, 64, 64, "64x64 32bpp ARGB"},
@@ -391,7 +391,7 @@  int intel_vgpu_decode_cursor_plane(struct intel_vgpu *vgpu,
 
 #define SPRITE_FORMAT_NUM	(1 << 3)
 
-static struct pixel_format sprite_pixel_formats[SPRITE_FORMAT_NUM] = {
+static const struct pixel_format sprite_pixel_formats[SPRITE_FORMAT_NUM] = {
 	[0x0] = {DRM_FORMAT_YUV422, 16, "YUV 16-bit 4:2:2 packed"},
 	[0x1] = {DRM_FORMAT_XRGB2101010, 32, "RGB 32-bit 2:10:10:10"},
 	[0x2] = {DRM_FORMAT_XRGB8888, 32, "RGB 32-bit 8:8:8:8"},