diff mbox series

[resend] atomisp: fix potential NULL pointer dereferences

Message ID fc6a20a9-dddb-626c-460f-3e8c38be4432@xs4all.nl (mailing list archive)
State New, archived
Headers show
Series [resend] atomisp: fix potential NULL pointer dereferences | expand

Commit Message

Hans Verkuil Oct. 24, 2022, 4:02 p.m. UTC
The asd pointer is used in lockdep_assert_held() before the check if
asd is NULL.

This fixes two smatch warnings:

drivers/staging/media/atomisp/pci/atomisp_cmd.c:3697 atomisp_handle_parameter_and_buffer() warn: variable dereferenced before check 'asd' (see line 3695)
drivers/staging/media/atomisp/pci/atomisp_cmd.c:3779 atomisp_set_parameters() warn: variable dereferenced before check 'asd' (see line 3777)

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
Not sure what happened with the first attempt to post the patch, retrying...
---
diff mbox series

Patch

diff --git a/drivers/staging/media/atomisp/pci/atomisp_cmd.c b/drivers/staging/media/atomisp/pci/atomisp_cmd.c
index 90f25cc22227..eeb66b3b79ab 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_cmd.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_cmd.c
@@ -3692,14 +3692,14 @@  void atomisp_handle_parameter_and_buffer(struct atomisp_video_pipe *pipe)
 	unsigned long irqflags;
 	bool need_to_enqueue_buffer = false;
 
-	lockdep_assert_held(&asd->isp->mutex);
-
 	if (!asd) {
 		dev_err(pipe->isp->dev, "%s(): asd is NULL, device is %s\n",
 			__func__, pipe->vdev.name);
 		return;
 	}
 
+	lockdep_assert_held(&asd->isp->mutex);
+
 	if (atomisp_is_vf_pipe(pipe))
 		return;
 
@@ -3774,14 +3774,14 @@  int atomisp_set_parameters(struct video_device *vdev,
 	struct atomisp_css_params *css_param = &asd->params.css_param;
 	int ret;
 
-	lockdep_assert_held(&asd->isp->mutex);
-
 	if (!asd) {
 		dev_err(pipe->isp->dev, "%s(): asd is NULL, device is %s\n",
 			__func__, vdev->name);
 		return -EINVAL;
 	}
 
+	lockdep_assert_held(&asd->isp->mutex);
+
 	if (!asd->stream_env[ATOMISP_INPUT_STREAM_GENERAL].stream) {
 		dev_err(asd->isp->dev, "%s: internal error!\n", __func__);
 		return -EINVAL;