Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: mtk-vcodec: avoid unneeded pointer-to-long conversions

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>

authored by

Alexandre Courbot and committed by
Mauro Carvalho Chehab
86aed3f5 d13b3cdc

+46 -46
+1 -1
drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
··· 273 273 274 274 const struct vdec_common_if *dec_if; 275 275 const struct venc_common_if *enc_if; 276 - unsigned long drv_handle; 276 + void *drv_handle; 277 277 278 278 struct vdec_pic_info picinfo; 279 279 int dpb_size;
+6 -6
drivers/media/platform/mtk-vcodec/vdec/vdec_h264_if.c
··· 266 266 mtk_vcodec_debug(inst, "sz=%d", *dpb_sz); 267 267 } 268 268 269 - static int vdec_h264_init(struct mtk_vcodec_ctx *ctx, unsigned long *h_vdec) 269 + static int vdec_h264_init(struct mtk_vcodec_ctx *ctx) 270 270 { 271 271 struct vdec_h264_inst *inst = NULL; 272 272 int err; ··· 295 295 296 296 mtk_vcodec_debug(inst, "H264 Instance >> %p", inst); 297 297 298 - *h_vdec = (unsigned long)inst; 298 + ctx->drv_handle = inst; 299 299 return 0; 300 300 301 301 error_deinit: ··· 306 306 return err; 307 307 } 308 308 309 - static void vdec_h264_deinit(unsigned long h_vdec) 309 + static void vdec_h264_deinit(void *h_vdec) 310 310 { 311 311 struct vdec_h264_inst *inst = (struct vdec_h264_inst *)h_vdec; 312 312 ··· 331 331 return -1; 332 332 } 333 333 334 - static int vdec_h264_decode(unsigned long h_vdec, struct mtk_vcodec_mem *bs, 334 + static int vdec_h264_decode(void *h_vdec, struct mtk_vcodec_mem *bs, 335 335 struct vdec_fb *fb, bool *res_chg) 336 336 { 337 337 struct vdec_h264_inst *inst = (struct vdec_h264_inst *)h_vdec; ··· 451 451 list->count--; 452 452 } 453 453 454 - static int vdec_h264_get_param(unsigned long h_vdec, 455 - enum vdec_get_param_type type, void *out) 454 + static int vdec_h264_get_param(void *h_vdec, enum vdec_get_param_type type, 455 + void *out) 456 456 { 457 457 struct vdec_h264_inst *inst = (struct vdec_h264_inst *)h_vdec; 458 458
+6 -6
drivers/media/platform/mtk-vcodec/vdec/vdec_vp8_if.c
··· 388 388 inst->vsi->dec.working_buf_dma = 0; 389 389 } 390 390 391 - static int vdec_vp8_init(struct mtk_vcodec_ctx *ctx, unsigned long *h_vdec) 391 + static int vdec_vp8_init(struct mtk_vcodec_ctx *ctx) 392 392 { 393 393 struct vdec_vp8_inst *inst; 394 394 int err; ··· 419 419 get_hw_reg_base(inst); 420 420 mtk_vcodec_debug(inst, "VP8 Instance >> %p", inst); 421 421 422 - *h_vdec = (unsigned long)inst; 422 + ctx->drv_handle = inst; 423 423 return 0; 424 424 425 425 error_deinit: ··· 429 429 return err; 430 430 } 431 431 432 - static int vdec_vp8_decode(unsigned long h_vdec, struct mtk_vcodec_mem *bs, 432 + static int vdec_vp8_decode(void *h_vdec, struct mtk_vcodec_mem *bs, 433 433 struct vdec_fb *fb, bool *res_chg) 434 434 { 435 435 struct vdec_vp8_inst *inst = (struct vdec_vp8_inst *)h_vdec; ··· 565 565 cr->left, cr->top, cr->width, cr->height); 566 566 } 567 567 568 - static int vdec_vp8_get_param(unsigned long h_vdec, 569 - enum vdec_get_param_type type, void *out) 568 + static int vdec_vp8_get_param(void *h_vdec, enum vdec_get_param_type type, 569 + void *out) 570 570 { 571 571 struct vdec_vp8_inst *inst = (struct vdec_vp8_inst *)h_vdec; 572 572 ··· 599 599 return 0; 600 600 } 601 601 602 - static void vdec_vp8_deinit(unsigned long h_vdec) 602 + static void vdec_vp8_deinit(void *h_vdec) 603 603 { 604 604 struct vdec_vp8_inst *inst = (struct vdec_vp8_inst *)h_vdec; 605 605
+7 -7
drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c
··· 757 757 return 0; 758 758 } 759 759 760 - static void vdec_vp9_deinit(unsigned long h_vdec) 760 + static void vdec_vp9_deinit(void *h_vdec) 761 761 { 762 762 struct vdec_vp9_inst *inst = (struct vdec_vp9_inst *)h_vdec; 763 763 struct mtk_vcodec_mem *mem; ··· 779 779 vp9_free_inst(inst); 780 780 } 781 781 782 - static int vdec_vp9_init(struct mtk_vcodec_ctx *ctx, unsigned long *h_vdec) 782 + static int vdec_vp9_init(struct mtk_vcodec_ctx *ctx) 783 783 { 784 784 struct vdec_vp9_inst *inst; 785 785 ··· 803 803 inst->vsi = (struct vdec_vp9_vsi *)inst->vpu.vsi; 804 804 init_all_fb_lists(inst); 805 805 806 - (*h_vdec) = (unsigned long)inst; 806 + ctx->drv_handle = inst; 807 807 return 0; 808 808 809 809 err_deinit_inst: ··· 812 812 return -EINVAL; 813 813 } 814 814 815 - static int vdec_vp9_decode(unsigned long h_vdec, struct mtk_vcodec_mem *bs, 816 - struct vdec_fb *fb, bool *res_chg) 815 + static int vdec_vp9_decode(void *h_vdec, struct mtk_vcodec_mem *bs, 816 + struct vdec_fb *fb, bool *res_chg) 817 817 { 818 818 int ret = 0; 819 819 struct vdec_vp9_inst *inst = (struct vdec_vp9_inst *)h_vdec; ··· 969 969 cr->left, cr->top, cr->width, cr->height); 970 970 } 971 971 972 - static int vdec_vp9_get_param(unsigned long h_vdec, 973 - enum vdec_get_param_type type, void *out) 972 + static int vdec_vp9_get_param(void *h_vdec, enum vdec_get_param_type type, 973 + void *out) 974 974 { 975 975 struct vdec_vp9_inst *inst = (struct vdec_vp9_inst *)h_vdec; 976 976 int ret = 0;
+4 -4
drivers/media/platform/mtk-vcodec/vdec_drv_base.h
··· 17 17 * @ctx : [in] mtk v4l2 context 18 18 * @h_vdec : [out] driver handle 19 19 */ 20 - int (*init)(struct mtk_vcodec_ctx *ctx, unsigned long *h_vdec); 20 + int (*init)(struct mtk_vcodec_ctx *ctx); 21 21 22 22 /** 23 23 * (*decode)() - trigger decode ··· 26 26 * @fb : [in] frame buffer to store decoded frame 27 27 * @res_chg : [out] resolution change happen 28 28 */ 29 - int (*decode)(unsigned long h_vdec, struct mtk_vcodec_mem *bs, 29 + int (*decode)(void *h_vdec, struct mtk_vcodec_mem *bs, 30 30 struct vdec_fb *fb, bool *res_chg); 31 31 32 32 /** ··· 35 35 * @type : [in] input parameter type 36 36 * @out : [out] buffer to store query result 37 37 */ 38 - int (*get_param)(unsigned long h_vdec, enum vdec_get_param_type type, 38 + int (*get_param)(void *h_vdec, enum vdec_get_param_type type, 39 39 void *out); 40 40 41 41 /** 42 42 * (*deinit)() - deinitialize driver. 43 43 * @h_vdec : [in] driver handle to be deinit 44 44 */ 45 - void (*deinit)(unsigned long h_vdec); 45 + void (*deinit)(void *h_vdec); 46 46 }; 47 47 48 48 #endif
+5 -5
drivers/media/platform/mtk-vcodec/vdec_drv_if.c
··· 39 39 40 40 mtk_vdec_lock(ctx); 41 41 mtk_vcodec_dec_clock_on(&ctx->dev->pm); 42 - ret = ctx->dec_if->init(ctx, &ctx->drv_handle); 42 + ret = ctx->dec_if->init(ctx); 43 43 mtk_vcodec_dec_clock_off(&ctx->dev->pm); 44 44 mtk_vdec_unlock(ctx); 45 45 ··· 66 66 } 67 67 } 68 68 69 - if (ctx->drv_handle == 0) 69 + if (!ctx->drv_handle) 70 70 return -EIO; 71 71 72 72 mtk_vdec_lock(ctx); ··· 89 89 { 90 90 int ret = 0; 91 91 92 - if (ctx->drv_handle == 0) 92 + if (!ctx->drv_handle) 93 93 return -EIO; 94 94 95 95 mtk_vdec_lock(ctx); ··· 101 101 102 102 void vdec_if_deinit(struct mtk_vcodec_ctx *ctx) 103 103 { 104 - if (ctx->drv_handle == 0) 104 + if (!ctx->drv_handle) 105 105 return; 106 106 107 107 mtk_vdec_lock(ctx); ··· 110 110 mtk_vcodec_dec_clock_off(&ctx->dev->pm); 111 111 mtk_vdec_unlock(ctx); 112 112 113 - ctx->drv_handle = 0; 113 + ctx->drv_handle = NULL; 114 114 }
+5 -5
drivers/media/platform/mtk-vcodec/venc/venc_h264_if.c
··· 458 458 memset(p, 0xff, size); 459 459 } 460 460 461 - static int h264_enc_init(struct mtk_vcodec_ctx *ctx, unsigned long *handle) 461 + static int h264_enc_init(struct mtk_vcodec_ctx *ctx) 462 462 { 463 463 int ret = 0; 464 464 struct venc_h264_inst *inst; ··· 484 484 if (ret) 485 485 kfree(inst); 486 486 else 487 - (*handle) = (unsigned long)inst; 487 + ctx->drv_handle = inst; 488 488 489 489 return ret; 490 490 } 491 491 492 - static int h264_enc_encode(unsigned long handle, 492 + static int h264_enc_encode(void *handle, 493 493 enum venc_start_opt opt, 494 494 struct venc_frm_buf *frm_buf, 495 495 struct mtk_vcodec_mem *bs_buf, ··· 584 584 return ret; 585 585 } 586 586 587 - static int h264_enc_set_param(unsigned long handle, 587 + static int h264_enc_set_param(void *handle, 588 588 enum venc_set_param_type type, 589 589 struct venc_enc_param *enc_prm) 590 590 { ··· 637 637 return ret; 638 638 } 639 639 640 - static int h264_enc_deinit(unsigned long handle) 640 + static int h264_enc_deinit(void *handle) 641 641 { 642 642 int ret = 0; 643 643 struct venc_h264_inst *inst = (struct venc_h264_inst *)handle;
+5 -5
drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c
··· 323 323 return ret; 324 324 } 325 325 326 - static int vp8_enc_init(struct mtk_vcodec_ctx *ctx, unsigned long *handle) 326 + static int vp8_enc_init(struct mtk_vcodec_ctx *ctx) 327 327 { 328 328 int ret = 0; 329 329 struct venc_vp8_inst *inst; ··· 349 349 if (ret) 350 350 kfree(inst); 351 351 else 352 - (*handle) = (unsigned long)inst; 352 + ctx->drv_handle = inst; 353 353 354 354 return ret; 355 355 } 356 356 357 - static int vp8_enc_encode(unsigned long handle, 357 + static int vp8_enc_encode(void *handle, 358 358 enum venc_start_opt opt, 359 359 struct venc_frm_buf *frm_buf, 360 360 struct mtk_vcodec_mem *bs_buf, ··· 391 391 return ret; 392 392 } 393 393 394 - static int vp8_enc_set_param(unsigned long handle, 394 + static int vp8_enc_set_param(void *handle, 395 395 enum venc_set_param_type type, 396 396 struct venc_enc_param *enc_prm) 397 397 { ··· 442 442 return ret; 443 443 } 444 444 445 - static int vp8_enc_deinit(unsigned long handle) 445 + static int vp8_enc_deinit(void *handle) 446 446 { 447 447 int ret = 0; 448 448 struct venc_vp8_inst *inst = (struct venc_vp8_inst *)handle;
+4 -4
drivers/media/platform/mtk-vcodec/venc_drv_base.h
··· 19 19 * @ctx: [in] mtk v4l2 context 20 20 * @handle: [out] driver handle 21 21 */ 22 - int (*init)(struct mtk_vcodec_ctx *ctx, unsigned long *handle); 22 + int (*init)(struct mtk_vcodec_ctx *ctx); 23 23 24 24 /** 25 25 * (*encode)() - trigger encode ··· 29 29 * @bs_buf: [in] bitstream buffer to store output bitstream 30 30 * @result: [out] encode result 31 31 */ 32 - int (*encode)(unsigned long handle, enum venc_start_opt opt, 32 + int (*encode)(void *handle, enum venc_start_opt opt, 33 33 struct venc_frm_buf *frm_buf, 34 34 struct mtk_vcodec_mem *bs_buf, 35 35 struct venc_done_result *result); ··· 40 40 * @type: [in] parameter type 41 41 * @in: [in] buffer to store the parameter 42 42 */ 43 - int (*set_param)(unsigned long handle, enum venc_set_param_type type, 43 + int (*set_param)(void *handle, enum venc_set_param_type type, 44 44 struct venc_enc_param *in); 45 45 46 46 /** 47 47 * (*deinit)() - deinitialize driver. 48 48 * @handle: [in] driver handle 49 49 */ 50 - int (*deinit)(unsigned long handle); 50 + int (*deinit)(void *handle); 51 51 }; 52 52 53 53 #endif
+3 -3
drivers/media/platform/mtk-vcodec/venc_drv_if.c
··· 37 37 38 38 mtk_venc_lock(ctx); 39 39 mtk_vcodec_enc_clock_on(&ctx->dev->pm); 40 - ret = ctx->enc_if->init(ctx, (unsigned long *)&ctx->drv_handle); 40 + ret = ctx->enc_if->init(ctx); 41 41 mtk_vcodec_enc_clock_off(&ctx->dev->pm); 42 42 mtk_venc_unlock(ctx); 43 43 ··· 89 89 { 90 90 int ret = 0; 91 91 92 - if (ctx->drv_handle == 0) 92 + if (!ctx->drv_handle) 93 93 return 0; 94 94 95 95 mtk_venc_lock(ctx); ··· 98 98 mtk_vcodec_enc_clock_off(&ctx->dev->pm); 99 99 mtk_venc_unlock(ctx); 100 100 101 - ctx->drv_handle = 0; 101 + ctx->drv_handle = NULL; 102 102 103 103 return ret; 104 104 }