]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
media: mtk-vcodec: avoid unneeded pointer-to-long conversions
authorAlexandre Courbot <acourbot@chromium.org>
Fri, 14 Jun 2019 07:56:21 +0000 (03:56 -0400)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Fri, 21 Jun 2019 21:09:30 +0000 (17:09 -0400)
The interface used to communicate with the firmware casts pointers
into unsigned longs and back again in order to store private
references, all of this for pointers that remain purely in the kernel.
Replace these unsigned longs with void pointers to make the code a bit
sturdier and easier to follow.

Also simplify some interfaces by removing arguments that could be
infered from others.

Signed-off-by: Alexandre Courbot <acourbot@chromium.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
[hverkuil-cisco@xs4all.nl: fix checkpatch alignment warning]
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
drivers/media/platform/mtk-vcodec/vdec/vdec_h264_if.c
drivers/media/platform/mtk-vcodec/vdec/vdec_vp8_if.c
drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c
drivers/media/platform/mtk-vcodec/vdec_drv_base.h
drivers/media/platform/mtk-vcodec/vdec_drv_if.c
drivers/media/platform/mtk-vcodec/venc/venc_h264_if.c
drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c
drivers/media/platform/mtk-vcodec/venc_drv_base.h
drivers/media/platform/mtk-vcodec/venc_drv_if.c

index c1422739dab472af84bc5805985210f8f023e810..c95de5d08dda87469c01a8e4797882d3d0548bc6 100644 (file)
@@ -273,7 +273,7 @@ struct mtk_vcodec_ctx {
 
        const struct vdec_common_if *dec_if;
        const struct venc_common_if *enc_if;
-       unsigned long drv_handle;
+       void *drv_handle;
 
        struct vdec_pic_info picinfo;
        int dpb_size;
index c035f744b1f127e2586339b0aa875e2d9dab3d3f..67a7d4f813d583dd3f5e92930080b61056ce7115 100644 (file)
@@ -266,7 +266,7 @@ static void get_dpb_size(struct vdec_h264_inst *inst, unsigned int *dpb_sz)
        mtk_vcodec_debug(inst, "sz=%d", *dpb_sz);
 }
 
-static int vdec_h264_init(struct mtk_vcodec_ctx *ctx, unsigned long *h_vdec)
+static int vdec_h264_init(struct mtk_vcodec_ctx *ctx)
 {
        struct vdec_h264_inst *inst = NULL;
        int err;
@@ -295,7 +295,7 @@ static int vdec_h264_init(struct mtk_vcodec_ctx *ctx, unsigned long *h_vdec)
 
        mtk_vcodec_debug(inst, "H264 Instance >> %p", inst);
 
-       *h_vdec = (unsigned long)inst;
+       ctx->drv_handle = inst;
        return 0;
 
 error_deinit:
@@ -306,7 +306,7 @@ static int vdec_h264_init(struct mtk_vcodec_ctx *ctx, unsigned long *h_vdec)
        return err;
 }
 
-static void vdec_h264_deinit(unsigned long h_vdec)
+static void vdec_h264_deinit(void *h_vdec)
 {
        struct vdec_h264_inst *inst = (struct vdec_h264_inst *)h_vdec;
 
@@ -331,7 +331,7 @@ static int find_start_code(unsigned char *data, unsigned int data_sz)
        return -1;
 }
 
-static int vdec_h264_decode(unsigned long h_vdec, struct mtk_vcodec_mem *bs,
+static int vdec_h264_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
                            struct vdec_fb *fb, bool *res_chg)
 {
        struct vdec_h264_inst *inst = (struct vdec_h264_inst *)h_vdec;
@@ -451,8 +451,8 @@ static void vdec_h264_get_fb(struct vdec_h264_inst *inst,
        list->count--;
 }
 
-static int vdec_h264_get_param(unsigned long h_vdec,
-                              enum vdec_get_param_type type, void *out)
+static int vdec_h264_get_param(void *h_vdec, enum vdec_get_param_type type,
+                              void *out)
 {
        struct vdec_h264_inst *inst = (struct vdec_h264_inst *)h_vdec;
 
index 24f976f0d477f2542289cce5657fd3fcdd42d0f7..42e302650e693b8bc2d1a74f911558969806f6ec 100644 (file)
@@ -388,7 +388,7 @@ static void free_working_buf(struct vdec_vp8_inst *inst)
        inst->vsi->dec.working_buf_dma = 0;
 }
 
-static int vdec_vp8_init(struct mtk_vcodec_ctx *ctx, unsigned long *h_vdec)
+static int vdec_vp8_init(struct mtk_vcodec_ctx *ctx)
 {
        struct vdec_vp8_inst *inst;
        int err;
@@ -419,7 +419,7 @@ static int vdec_vp8_init(struct mtk_vcodec_ctx *ctx, unsigned long *h_vdec)
        get_hw_reg_base(inst);
        mtk_vcodec_debug(inst, "VP8 Instance >> %p", inst);
 
-       *h_vdec = (unsigned long)inst;
+       ctx->drv_handle = inst;
        return 0;
 
 error_deinit:
@@ -429,7 +429,7 @@ static int vdec_vp8_init(struct mtk_vcodec_ctx *ctx, unsigned long *h_vdec)
        return err;
 }
 
-static int vdec_vp8_decode(unsigned long h_vdec, struct mtk_vcodec_mem *bs,
+static int vdec_vp8_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
                           struct vdec_fb *fb, bool *res_chg)
 {
        struct vdec_vp8_inst *inst = (struct vdec_vp8_inst *)h_vdec;
@@ -565,8 +565,8 @@ static void get_crop_info(struct vdec_vp8_inst *inst, struct v4l2_rect *cr)
                         cr->left, cr->top, cr->width, cr->height);
 }
 
-static int vdec_vp8_get_param(unsigned long h_vdec,
-                             enum vdec_get_param_type type, void *out)
+static int vdec_vp8_get_param(void *h_vdec, enum vdec_get_param_type type,
+                             void *out)
 {
        struct vdec_vp8_inst *inst = (struct vdec_vp8_inst *)h_vdec;
 
@@ -599,7 +599,7 @@ static int vdec_vp8_get_param(unsigned long h_vdec,
        return 0;
 }
 
-static void vdec_vp8_deinit(unsigned long h_vdec)
+static void vdec_vp8_deinit(void *h_vdec)
 {
        struct vdec_vp8_inst *inst = (struct vdec_vp8_inst *)h_vdec;
 
index 9e6b630d7f5ba3c86e3797e9e9a5b60cb538d4ef..7935f97989b075fe441e002ffdaa7145a91a6912 100644 (file)
@@ -757,7 +757,7 @@ static int validate_vsi_array_indexes(struct vdec_vp9_inst *inst,
        return 0;
 }
 
-static void vdec_vp9_deinit(unsigned long h_vdec)
+static void vdec_vp9_deinit(void *h_vdec)
 {
        struct vdec_vp9_inst *inst = (struct vdec_vp9_inst *)h_vdec;
        struct mtk_vcodec_mem *mem;
@@ -779,7 +779,7 @@ static void vdec_vp9_deinit(unsigned long h_vdec)
        vp9_free_inst(inst);
 }
 
-static int vdec_vp9_init(struct mtk_vcodec_ctx *ctx, unsigned long *h_vdec)
+static int vdec_vp9_init(struct mtk_vcodec_ctx *ctx)
 {
        struct vdec_vp9_inst *inst;
 
@@ -803,7 +803,7 @@ static int vdec_vp9_init(struct mtk_vcodec_ctx *ctx, unsigned long *h_vdec)
        inst->vsi = (struct vdec_vp9_vsi *)inst->vpu.vsi;
        init_all_fb_lists(inst);
 
-       (*h_vdec) = (unsigned long)inst;
+       ctx->drv_handle = inst;
        return 0;
 
 err_deinit_inst:
@@ -812,8 +812,8 @@ static int vdec_vp9_init(struct mtk_vcodec_ctx *ctx, unsigned long *h_vdec)
        return -EINVAL;
 }
 
-static int vdec_vp9_decode(unsigned long h_vdec, struct mtk_vcodec_mem *bs,
-                  struct vdec_fb *fb, bool *res_chg)
+static int vdec_vp9_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
+                          struct vdec_fb *fb, bool *res_chg)
 {
        int ret = 0;
        struct vdec_vp9_inst *inst = (struct vdec_vp9_inst *)h_vdec;
@@ -969,8 +969,8 @@ static void get_crop_info(struct vdec_vp9_inst *inst, struct v4l2_rect *cr)
                         cr->left, cr->top, cr->width, cr->height);
 }
 
-static int vdec_vp9_get_param(unsigned long h_vdec,
-               enum vdec_get_param_type type, void *out)
+static int vdec_vp9_get_param(void *h_vdec, enum vdec_get_param_type type,
+                             void *out)
 {
        struct vdec_vp9_inst *inst = (struct vdec_vp9_inst *)h_vdec;
        int ret = 0;
index 2019aec71ddb753bed19eca9d4ca45dc8ef074e9..ceb4db4cb3bed8bc896da985b8b7cc193814e5c2 100644 (file)
@@ -17,7 +17,7 @@ struct vdec_common_if {
         * @ctx     : [in] mtk v4l2 context
         * @h_vdec  : [out] driver handle
         */
-       int (*init)(struct mtk_vcodec_ctx *ctx, unsigned long *h_vdec);
+       int (*init)(struct mtk_vcodec_ctx *ctx);
 
        /**
         * (*decode)() - trigger decode
@@ -26,7 +26,7 @@ struct vdec_common_if {
         * @fb      : [in] frame buffer to store decoded frame
         * @res_chg : [out] resolution change happen
         */
-       int (*decode)(unsigned long h_vdec, struct mtk_vcodec_mem *bs,
+       int (*decode)(void *h_vdec, struct mtk_vcodec_mem *bs,
                      struct vdec_fb *fb, bool *res_chg);
 
        /**
@@ -35,14 +35,14 @@ struct vdec_common_if {
         * @type   : [in] input parameter type
         * @out    : [out] buffer to store query result
         */
-       int (*get_param)(unsigned long h_vdec, enum vdec_get_param_type type,
+       int (*get_param)(void *h_vdec, enum vdec_get_param_type type,
                         void *out);
 
        /**
         * (*deinit)() - deinitialize driver.
         * @h_vdec : [in] driver handle to be deinit
         */
-       void (*deinit)(unsigned long h_vdec);
+       void (*deinit)(void *h_vdec);
 };
 
 #endif
index bd42d9028c420a49f9626849e39301bc9fb62686..8354404a7fc96da430bbb56517e32d97910f7321 100644 (file)
@@ -39,7 +39,7 @@ int vdec_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc)
 
        mtk_vdec_lock(ctx);
        mtk_vcodec_dec_clock_on(&ctx->dev->pm);
-       ret = ctx->dec_if->init(ctx, &ctx->drv_handle);
+       ret = ctx->dec_if->init(ctx);
        mtk_vcodec_dec_clock_off(&ctx->dev->pm);
        mtk_vdec_unlock(ctx);
 
@@ -66,7 +66,7 @@ int vdec_if_decode(struct mtk_vcodec_ctx *ctx, struct mtk_vcodec_mem *bs,
                }
        }
 
-       if (ctx->drv_handle == 0)
+       if (!ctx->drv_handle)
                return -EIO;
 
        mtk_vdec_lock(ctx);
@@ -89,7 +89,7 @@ int vdec_if_get_param(struct mtk_vcodec_ctx *ctx, enum vdec_get_param_type type,
 {
        int ret = 0;
 
-       if (ctx->drv_handle == 0)
+       if (!ctx->drv_handle)
                return -EIO;
 
        mtk_vdec_lock(ctx);
@@ -101,7 +101,7 @@ int vdec_if_get_param(struct mtk_vcodec_ctx *ctx, enum vdec_get_param_type type,
 
 void vdec_if_deinit(struct mtk_vcodec_ctx *ctx)
 {
-       if (ctx->drv_handle == 0)
+       if (!ctx->drv_handle)
                return;
 
        mtk_vdec_lock(ctx);
@@ -110,5 +110,5 @@ void vdec_if_deinit(struct mtk_vcodec_ctx *ctx)
        mtk_vcodec_dec_clock_off(&ctx->dev->pm);
        mtk_vdec_unlock(ctx);
 
-       ctx->drv_handle = 0;
+       ctx->drv_handle = NULL;
 }
index 21f2eaea207b9287c1c49d514616e6af7ed13103..0183dd395d44c781b7449215525cc78d112b5838 100644 (file)
@@ -458,7 +458,7 @@ static void h264_encode_filler(struct venc_h264_inst *inst, void *buf,
        memset(p, 0xff, size);
 }
 
-static int h264_enc_init(struct mtk_vcodec_ctx *ctx, unsigned long *handle)
+static int h264_enc_init(struct mtk_vcodec_ctx *ctx)
 {
        int ret = 0;
        struct venc_h264_inst *inst;
@@ -484,12 +484,12 @@ static int h264_enc_init(struct mtk_vcodec_ctx *ctx, unsigned long *handle)
        if (ret)
                kfree(inst);
        else
-               (*handle) = (unsigned long)inst;
+               ctx->drv_handle = inst;
 
        return ret;
 }
 
-static int h264_enc_encode(unsigned long handle,
+static int h264_enc_encode(void *handle,
                           enum venc_start_opt opt,
                           struct venc_frm_buf *frm_buf,
                           struct mtk_vcodec_mem *bs_buf,
@@ -584,7 +584,7 @@ static int h264_enc_encode(unsigned long handle,
        return ret;
 }
 
-static int h264_enc_set_param(unsigned long handle,
+static int h264_enc_set_param(void *handle,
                              enum venc_set_param_type type,
                              struct venc_enc_param *enc_prm)
 {
@@ -637,7 +637,7 @@ static int h264_enc_set_param(unsigned long handle,
        return ret;
 }
 
-static int h264_enc_deinit(unsigned long handle)
+static int h264_enc_deinit(void *handle)
 {
        int ret = 0;
        struct venc_h264_inst *inst = (struct venc_h264_inst *)handle;
index 81f87f6ec4355f4d168dfe8437422e0d9ad67bab..3787e75ca902d8d5b1a2dc3ce25129a7c33c1769 100644 (file)
@@ -323,7 +323,7 @@ static int vp8_enc_encode_frame(struct venc_vp8_inst *inst,
        return ret;
 }
 
-static int vp8_enc_init(struct mtk_vcodec_ctx *ctx, unsigned long *handle)
+static int vp8_enc_init(struct mtk_vcodec_ctx *ctx)
 {
        int ret = 0;
        struct venc_vp8_inst *inst;
@@ -349,12 +349,12 @@ static int vp8_enc_init(struct mtk_vcodec_ctx *ctx, unsigned long *handle)
        if (ret)
                kfree(inst);
        else
-               (*handle) = (unsigned long)inst;
+               ctx->drv_handle = inst;
 
        return ret;
 }
 
-static int vp8_enc_encode(unsigned long handle,
+static int vp8_enc_encode(void *handle,
                          enum venc_start_opt opt,
                          struct venc_frm_buf *frm_buf,
                          struct mtk_vcodec_mem *bs_buf,
@@ -391,7 +391,7 @@ static int vp8_enc_encode(unsigned long handle,
        return ret;
 }
 
-static int vp8_enc_set_param(unsigned long handle,
+static int vp8_enc_set_param(void *handle,
                             enum venc_set_param_type type,
                             struct venc_enc_param *enc_prm)
 {
@@ -442,7 +442,7 @@ static int vp8_enc_set_param(unsigned long handle,
        return ret;
 }
 
-static int vp8_enc_deinit(unsigned long handle)
+static int vp8_enc_deinit(void *handle)
 {
        int ret = 0;
        struct venc_vp8_inst *inst = (struct venc_vp8_inst *)handle;
index 09968a68db4205879df19cd5bd993f0940e4276b..3d718411dc73a96cd45810dacda1a91f8d10cb71 100644 (file)
@@ -19,7 +19,7 @@ struct venc_common_if {
         * @ctx:        [in] mtk v4l2 context
         * @handle: [out] driver handle
         */
-       int (*init)(struct mtk_vcodec_ctx *ctx, unsigned long *handle);
+       int (*init)(struct mtk_vcodec_ctx *ctx);
 
        /**
         * (*encode)() - trigger encode
@@ -29,7 +29,7 @@ struct venc_common_if {
         * @bs_buf: [in] bitstream buffer to store output bitstream
         * @result: [out] encode result
         */
-       int (*encode)(unsigned long handle, enum venc_start_opt opt,
+       int (*encode)(void *handle, enum venc_start_opt opt,
                      struct venc_frm_buf *frm_buf,
                      struct mtk_vcodec_mem *bs_buf,
                      struct venc_done_result *result);
@@ -40,14 +40,14 @@ struct venc_common_if {
         * @type: [in] parameter type
         * @in: [in] buffer to store the parameter
         */
-       int (*set_param)(unsigned long handle, enum venc_set_param_type type,
+       int (*set_param)(void *handle, enum venc_set_param_type type,
                         struct venc_enc_param *in);
 
        /**
         * (*deinit)() - deinitialize driver.
         * @handle: [in] driver handle
         */
-       int (*deinit)(unsigned long handle);
+       int (*deinit)(void *handle);
 };
 
 #endif
index 600c43c17e48b7dfeeecea401a3068a9f4ec7281..b5cc645f7c6826261d6e6e02b8de4212121d2c89 100644 (file)
@@ -37,7 +37,7 @@ int venc_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc)
 
        mtk_venc_lock(ctx);
        mtk_vcodec_enc_clock_on(&ctx->dev->pm);
-       ret = ctx->enc_if->init(ctx, (unsigned long *)&ctx->drv_handle);
+       ret = ctx->enc_if->init(ctx);
        mtk_vcodec_enc_clock_off(&ctx->dev->pm);
        mtk_venc_unlock(ctx);
 
@@ -89,7 +89,7 @@ int venc_if_deinit(struct mtk_vcodec_ctx *ctx)
 {
        int ret = 0;
 
-       if (ctx->drv_handle == 0)
+       if (!ctx->drv_handle)
                return 0;
 
        mtk_venc_lock(ctx);
@@ -98,7 +98,7 @@ int venc_if_deinit(struct mtk_vcodec_ctx *ctx)
        mtk_vcodec_enc_clock_off(&ctx->dev->pm);
        mtk_venc_unlock(ctx);
 
-       ctx->drv_handle = 0;
+       ctx->drv_handle = NULL;
 
        return ret;
 }