media: rzg2l-cru: Fix possible ERR_PTR deference
Subsystems (2)
PATCH 1/1 media: rzg2l-cru: Fix possible ERR_PTR deference
The media_pad_remote_pad_unique() can return ERR_PTR() on failure (-ENOTUNIQ or -ENOLINK), but the code was dereferencing the return value without checking for errors. Add IS_ERR() check before dereferencing the pointer.
--- drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c +6 -0
@@ -411,6 +411,12 @@ static int rzg2l_cru_get_virtual_channel(struct rzg2l_cru_dev *cru)int ret; remote_pad =media_pad_remote_pad_unique (&cru->ip.pads[RZG2L_CRU_IP_SINK ]); +if (IS_ERR (remote_pad)) { + ret =PTR_ERR (remote_pad); +dev_err (cru->dev,"Failed to get remote source pad: %d\n" , ret); +return ret; + } + ret =v4l2_subdev_call (cru->ip.remote, pad, get_frame_desc, remote_pad->index, &fd);if (ret <0 && ret != -ENOIOCTLCMD ) {dev_err (cru->dev,"get_frame_desc failed on IP remote subdev\n" );
Signature · 1 line
2.43.0
Quoted 4 lines · Alper Ak
The
media_pad_remote_pad_unique()can returnERR_PTR()on failure (-ENOTUNIQor-ENOLINK), but the code was dereferencing the return value without checking for errors. AddIS_ERR()check before dereferencing the pointer.
Have you seen this happening ?
Quoted 23 lines
Fixes d7d72dae81d5 ("media: rzg2l-cru: Retrieve virtual channel information")Signed-off-by Alper Ak <[email protected]>--- drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c +6
-0@@ -411,6 +411,12 @@ static int rzg2l_cru_get_virtual_channel(struct rzg2l_cru_dev *cru)int ret; remote_pad =media_pad_remote_pad_unique (&cru->ip.pads[RZG2L_CRU_IP_SINK ]); +if (IS_ERR (remote_pad)) { + ret =PTR_ERR (remote_pad); +dev_err (cru->dev,"Failed to get remote source pad: %d\n" , ret); +return ret; + } + ret =v4l2_subdev_call (cru->ip.remote, pad, get_frame_desc, remote_pad->index, &fd);if (ret <0 && ret != -ENOIOCTLCMD ) {dev_err (cru->dev,"get_frame_desc failed on IP remote subdev\n" );
Signature · 3 lines
Regards, Laurent Pinchart
Quoted 1 line
Have you seen this happening ?
No, I haven't seen this happen in practice. This was reported by static analysis tool. Since the function explicitly documents these error cases, it seemed appropriate to add defensive error checking to avoid potential ERR_PTR dereference.
Laurent Pinchart <[email protected]>, 8 Şub 2026 Paz, 00:27 tarihinde şunu yazdı:
Quoted 37 lines · Alper Ak
Quoted 4 lines
The
media_pad_remote_pad_unique()can returnERR_PTR()on failure (-ENOTUNIQor-ENOLINK), but the code was dereferencing the return value without checking for errors. AddIS_ERR()check before dereferencing the pointer.Have you seen this happening ?
Quoted 13 lines
Fixes d7d72dae81d5 ("media: rzg2l-cru: Retrieve virtual channel information")Signed-off-by Alper Ak <[email protected]>--- drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c +0
-0@@ -411,6 +411,12 @@ static int rzg2l_cru_get_virtual_channel(struct rzg2l_cru_dev *cru)int ret;drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c static int rzg2l_cru_get_virtual_channel(struct rzg2l_cru_dev *cru) · line 422
Quoted 10 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c +6
-0remote_pad =media_pad_remote_pad_unique (&cru->ip.pads[RZG2L_CRU_IP_SINK ]); +if (IS_ERR (remote_pad)) { + ret =PTR_ERR (remote_pad); +dev_err (cru->dev,"Failed to get remote source pad: %d\n" , ret); +return ret; + } + ret =v4l2_subdev_call (cru->ip.remote, pad, get_frame_desc, remote_pad->index, &fd);if (ret <0 && ret != -ENOIOCTLCMD ) {dev_err (cru->dev,"get_frame_desc failed on IP remote subdev\n" );--
Regards,Laurent Pinchart
Quoted 6 lines · Alper Ak
Quoted 1 line
Have you seen this happening ?
No, I haven't seen this happen in practice. This was reported by static analysis tool. Since the function explicitly documents these error cases, it seemed appropriate to add defensive error checking to avoid potential
ERR_PTRdereference.
It's a false positive, this can't happen in practice due to the MEDIA_PAD_FL_MUST_CONNECT flag being set on the RZG2L_CRU_IP_SINK pad.
In the future, please disclose usage of static analysis tools when you submit patches.
Quoted 32 lines
Laurent Pinchart, 8 Şub 2026 Paz, 00:27 tarihinde şunu yazdı:
Quoted 31 lines · Alper Ak
Quoted 4 lines
The
media_pad_remote_pad_unique()can returnERR_PTR()on failure (-ENOTUNIQor-ENOLINK), but the code was dereferencing the return value without checking for errors. AddIS_ERR()check before dereferencing the pointer.Have you seen this happening ?
Quoted 23 lines
Fixes d7d72dae81d5 ("media: rzg2l-cru: Retrieve virtual channel information")Signed-off-by Alper Ak <[email protected]>--- drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c +6
-0@@ -411,6 +411,12 @@ static int rzg2l_cru_get_virtual_channel(struct rzg2l_cru_dev *cru)int ret; remote_pad =media_pad_remote_pad_unique (&cru->ip.pads[RZG2L_CRU_IP_SINK ]); +if (IS_ERR (remote_pad)) { + ret =PTR_ERR (remote_pad); +dev_err (cru->dev,"Failed to get remote source pad: %d\n" , ret); +return ret; + } + ret =v4l2_subdev_call (cru->ip.remote, pad, get_frame_desc, remote_pad->index, &fd);if (ret <0 && ret != -ENOIOCTLCMD ) {dev_err (cru->dev,"get_frame_desc failed on IP remote subdev\n" );
Signature · 3 lines
Regards, Laurent Pinchart
Quoted 2 lines
No, I haven't seen this happen in practice. This was reported by static analysis tool.
* Did this tool get a special name?
* Was any background information published for it?
Quoted 3 lines
Since the function explicitly documents these
error cases, it seemed appropriate to add defensive error checking to avoid potentialERR_PTRdereference.
How do you think about to improve change descriptions accordingly?
Regards,
Markus