media: imx-jpeg: Constify static struct mxc_jpeg_fmt

It 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.

Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
This commit is contained in:
Rikard Falkeborn 2021-06-12 01:42:01 +02:00 committed by Mauro Carvalho Chehab
parent 682e69d7a2
commit 7ec1c4a57c
2 changed files with 17 additions and 17 deletions

View File

@ -62,7 +62,7 @@
#include "mxc-jpeg-hw.h" #include "mxc-jpeg-hw.h"
#include "mxc-jpeg.h" #include "mxc-jpeg.h"
static struct mxc_jpeg_fmt mxc_formats[] = { static const struct mxc_jpeg_fmt mxc_formats[] = {
{ {
.name = "JPEG", .name = "JPEG",
.fourcc = V4L2_PIX_FMT_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); 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) struct v4l2_fmtdesc *f, u32 type)
{ {
int i, num = 0; int i, num = 0;
@ -368,13 +368,13 @@ static int enum_fmt(struct mxc_jpeg_fmt *mxc_formats, int n,
return 0; return 0;
} }
static struct mxc_jpeg_fmt *mxc_jpeg_find_format(struct mxc_jpeg_ctx *ctx, static const struct mxc_jpeg_fmt *mxc_jpeg_find_format(struct mxc_jpeg_ctx *ctx,
u32 pixelformat) u32 pixelformat)
{ {
unsigned int k; unsigned int k;
for (k = 0; k < MXC_JPEG_NUM_FORMATS; 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) if (fmt->fourcc == pixelformat)
return fmt; return fmt;
@ -1536,7 +1536,7 @@ static int mxc_jpeg_enum_fmt_vid_out(struct file *file, void *priv,
MXC_JPEG_FMT_TYPE_RAW); 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 mxc_jpeg_ctx *ctx, int q_type)
{ {
struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp; 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_ctx *ctx = mxc_jpeg_fh_to_ctx(priv);
struct mxc_jpeg_dev *jpeg = ctx->mxc_jpeg; struct mxc_jpeg_dev *jpeg = ctx->mxc_jpeg;
struct device *dev = jpeg->dev; struct device *dev = jpeg->dev;
struct mxc_jpeg_fmt *fmt; const struct mxc_jpeg_fmt *fmt;
u32 fourcc = f->fmt.pix_mp.pixelformat; u32 fourcc = f->fmt.pix_mp.pixelformat;
int q_type = (jpeg->mode == MXC_JPEG_DECODE) ? 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_ctx *ctx = mxc_jpeg_fh_to_ctx(priv);
struct mxc_jpeg_dev *jpeg = ctx->mxc_jpeg; struct mxc_jpeg_dev *jpeg = ctx->mxc_jpeg;
struct device *dev = jpeg->dev; struct device *dev = jpeg->dev;
struct mxc_jpeg_fmt *fmt; const struct mxc_jpeg_fmt *fmt;
u32 fourcc = f->fmt.pix_mp.pixelformat; u32 fourcc = f->fmt.pix_mp.pixelformat;
int q_type = (jpeg->mode == MXC_JPEG_ENCODE) ? int q_type = (jpeg->mode == MXC_JPEG_ENCODE) ?

View File

@ -51,7 +51,7 @@ enum mxc_jpeg_mode {
* @flags: flags describing format applicability * @flags: flags describing format applicability
*/ */
struct mxc_jpeg_fmt { struct mxc_jpeg_fmt {
char *name; const char *name;
u32 fourcc; u32 fourcc;
enum v4l2_jpeg_chroma_subsampling subsampling; enum v4l2_jpeg_chroma_subsampling subsampling;
int nc; int nc;
@ -74,14 +74,14 @@ struct mxc_jpeg_desc {
} __packed; } __packed;
struct mxc_jpeg_q_data { struct mxc_jpeg_q_data {
struct mxc_jpeg_fmt *fmt; const struct mxc_jpeg_fmt *fmt;
u32 sizeimage[MXC_JPEG_MAX_PLANES]; u32 sizeimage[MXC_JPEG_MAX_PLANES];
u32 bytesperline[MXC_JPEG_MAX_PLANES]; u32 bytesperline[MXC_JPEG_MAX_PLANES];
int w; int w;
int w_adjusted; int w_adjusted;
int h; int h;
int h_adjusted; int h_adjusted;
unsigned int sequence; unsigned int sequence;
}; };
struct mxc_jpeg_ctx { struct mxc_jpeg_ctx {