media: imx-jpeg: Constify a few static structs
Subsystems (2)
cover media: imx-jpeg: Constify a few static structs
Constify two structs that are never modified.
The first patch constifies a static v4l2_m2m_ops struct which contains function pointers.
The second constifies mxc_jpeg_fmt, which contains read-only data. In order to do that, a number of function arguments, return values and pointers was made const as well.
Rikard Falkeborn (2):
media: imx-jpeg: Constify static struct v4l2_m2m_ops
media: imx-jpeg: Constify static struct mxc_jpeg_fmt
drivers/media/platform/imx-jpeg/mxc-jpeg.c | 18 +++++++++--------- drivers/media/platform/imx-jpeg/mxc-jpeg.h | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-)
Signature · 1 line
2.32.0
PATCH 1/2 media: imx-jpeg: Constify static struct v4l2_m2m_ops
The only usage of mxc_jpeg_m2m_ops is to pass its address to v4l2_m2m_init() which takes a pointer to const struct v4l2_m2m_ops. Make it const to allow the compiler to put it in read-only memory.
--- drivers/media/platform/imx-jpeg/mxc-jpeg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/imx-jpeg/mxc-jpeg.c +1 -1
@@ -1890,7 +1890,7 @@ static const struct v4l2_file_operations mxc_jpeg_fops = { .mmap = v4l2_m2m_fop_mmap, }; -static struct v4l2_m2m_ops mxc_jpeg_m2m_ops = { +static const struct v4l2_m2m_ops mxc_jpeg_m2m_ops = { .device_run = mxc_jpeg_device_run, };
Signature · 1 line
2.32.0
PATCH 2/2 media: imx-jpeg: Constify static struct mxc_jpeg_fmt
In reply to Rikard FalkebornIt is only read-from, so make it const. In order to be able to do this, constify all places where mxc_jpeg_fmt is used, in function arguments, return values and pointers. On top of that, make the name a pointer to const char.
On aarch64, this shrinks object code size with 550 bytes with gcc 11.1.0, and almost 2kB with clang 12.0.0.
--- drivers/media/platform/imx-jpeg/mxc-jpeg.c | 16 ++++++++-------- drivers/media/platform/imx-jpeg/mxc-jpeg.h | 18 +++++++++--------- 2 files changed, 17 insertions(+), 17 deletions(-)
drivers/media/platform/imx-jpeg/mxc-jpeg.c +8 -8
@@ -62,7 +62,7 @@#include "mxc-jpeg-hw.h" #include "mxc-jpeg.h" -static struct mxc_jpeg_fmt mxc_formats[] = { +static const struct mxc_jpeg_fmt mxc_formats[] = { { .name ="JPEG" , .fourcc =V4L2_PIX_FMT_JPEG ,
@@ -341,7 +341,7 @@ static inline struct mxc_jpeg_ctx *mxc_jpeg_fh_to_ctx(struct v4l2_fh *fh) return container_of(fh, struct mxc_jpeg_ctx, fh); } -static int enum_fmt (struct mxc_jpeg_fmt *mxc_formats,int n, +static int enum_fmt (const struct mxc_jpeg_fmt *mxc_formats,int n,struct v4l2_fmtdesc *f,u32 type) {int i, num =0 ;
@@ -368,13 +368,13 @@ static int enum_fmt(struct mxc_jpeg_fmt *mxc_formats, int n,return 0 ; } -static struct mxc_jpeg_fmt *mxc_jpeg_find_format (struct mxc_jpeg_ctx *ctx, -u32 pixelformat) +static const struct mxc_jpeg_fmt *mxc_jpeg_find_format (struct mxc_jpeg_ctx *ctx, +u32 pixelformat) {unsigned int k;for (k =0 ; k <MXC_JPEG_NUM_FORMATS ; k++) { -struct mxc_jpeg_fmt *fmt = &mxc_formats[k]; +const struct mxc_jpeg_fmt *fmt = &mxc_formats[k];if (fmt->fourcc == pixelformat)return fmt;
@@ -1536,7 +1536,7 @@ static int mxc_jpeg_enum_fmt_vid_out(struct file *file, void *priv, MXC_JPEG_FMT_TYPE_RAW); } -static int mxc_jpeg_try_fmt (struct v4l2_format *f,struct mxc_jpeg_fmt *fmt, +static int mxc_jpeg_try_fmt (struct v4l2_format *f,const struct mxc_jpeg_fmt *fmt,struct mxc_jpeg_ctx *ctx,int q_type) {struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
@@ -1612,7 +1612,7 @@ static int mxc_jpeg_try_fmt_vid_cap(struct file *file, void *priv,struct mxc_jpeg_ctx *ctx =mxc_jpeg_fh_to_ctx (priv);struct mxc_jpeg_dev *jpeg = ctx->mxc_jpeg;struct device *dev = jpeg->dev; -struct mxc_jpeg_fmt *fmt; +const struct mxc_jpeg_fmt *fmt;u32 fourcc = f->fmt.pix_mp.pixelformat; int q_type = (jpeg->mode == MXC_JPEG_DECODE) ?
@@ -1643,7 +1643,7 @@ static int mxc_jpeg_try_fmt_vid_out(struct file *file, void *priv,struct mxc_jpeg_ctx *ctx =mxc_jpeg_fh_to_ctx (priv);struct mxc_jpeg_dev *jpeg = ctx->mxc_jpeg;struct device *dev = jpeg->dev; -struct mxc_jpeg_fmt *fmt; +const struct mxc_jpeg_fmt *fmt;u32 fourcc = f->fmt.pix_mp.pixelformat; int q_type = (jpeg->mode == MXC_JPEG_ENCODE) ?
drivers/media/platform/imx-jpeg/mxc-jpeg.h +9 -9
@@ -51,7 +51,7 @@ enum mxc_jpeg_mode {* @flags: flags describing format applicability */ struct mxc_jpeg_fmt { -char *name; +const char *name;u32 fourcc;enum v4l2_jpeg_chroma_subsampling subsampling;int nc;
@@ -74,14 +74,14 @@ struct mxc_jpeg_desc { } __packed;struct mxc_jpeg_q_data { -struct mxc_jpeg_fmt *fmt; -u32 sizeimage[MXC_JPEG_MAX_PLANES ]; -u32 bytesperline[MXC_JPEG_MAX_PLANES ]; -int w; -int w_adjusted; -int h; -int h_adjusted; -unsigned int sequence; +const struct mxc_jpeg_fmt *fmt; +u32 sizeimage[MXC_JPEG_MAX_PLANES ]; +u32 bytesperline[MXC_JPEG_MAX_PLANES ]; +int w; +int w_adjusted; +int h; +int h_adjusted; +unsigned int sequence; };struct mxc_jpeg_ctx {
Signature · 1 line
2.32.0