[PATCH 11/65] media: Replace file->private_data access with custom functions
Lukasz Stelmach
l.stelmach at samsung.com
Mon Aug 18 07:10:40 PDT 2025
It was <2025-08-02 sob 11:22>, when Jacopo Mondi wrote:
> From: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
>
> Accessing file->private_data manually to retrieve the v4l2_fh pointer is
> error-prone, as the field is a void * and will happily cast implicitly
> to any pointer type.
>
> Replace all remaining locations that read the v4l2_fh pointer directly
> from file->private_data and cast it to driver-specific file handle
> structures with driver-specific functions that use file_to_v4l2_fh() and
> perform the same cast.
>
> No functional change is intended, this only paves the way to remove
> direct accesses to file->private_data and make V4L2 drivers safer.
> Other accesses to the field will be addressed separately.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
> Signed-off-by: Jacopo Mondi <jacopo.mondi at ideasonboard.com>
> ---
[...]
> diff --git a/drivers/media/platform/samsung/s5p-g2d/g2d.c b/drivers/media/platform/samsung/s5p-g2d/g2d.c
> index ffed16a34493be2edbdaee13619467417487c1e7..44fcedbbc90a9863827aacbcd5f56d850cb552ea 100644
> --- a/drivers/media/platform/samsung/s5p-g2d/g2d.c
> +++ b/drivers/media/platform/samsung/s5p-g2d/g2d.c
> @@ -25,7 +25,10 @@
> #include "g2d.h"
> #include "g2d-regs.h"
>
> -#define fh2ctx(__fh) container_of(__fh, struct g2d_ctx, fh)
> +static inline struct g2d_ctx *file2ctx(struct file *filp)
> +{
> + return container_of(file_to_v4l2_fh(filp), struct g2d_ctx, fh);
> +}
>
> static struct g2d_fmt formats[] = {
> {
> @@ -272,7 +275,7 @@ static int g2d_open(struct file *file)
> static int g2d_release(struct file *file)
> {
> struct g2d_dev *dev = video_drvdata(file);
> - struct g2d_ctx *ctx = fh2ctx(file->private_data);
> + struct g2d_ctx *ctx = file2ctx(file);
>
> mutex_lock(&dev->mutex);
> v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
Acked-by: Lukasz Stelmach <l.stelmach at samsung.com>
[...]
--
Łukasz Stelmach
Samsung R&D Institute Poland
Samsung Electronics
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 487 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-mediatek/attachments/20250818/c545a287/attachment.sig>
More information about the Linux-mediatek
mailing list