linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: greybus: Fix potential NULL dereference
@ 2022-03-11  8:35 Haowen Bai
  2022-03-11  8:40 ` Viresh Kumar
  2022-03-11 11:32 ` Dan Carpenter
  0 siblings, 2 replies; 5+ messages in thread
From: Haowen Bai @ 2022-03-11  8:35 UTC (permalink / raw)
  To: vireshk, johan, elder, gregkh; +Cc: linux-staging, linux-kernel, Haowen Bai

Fix following coccicheck warning:
drivers/staging/greybus/bootrom.c:301:35-39: ERROR: fw is NULL but dereferenced.

When goto queue_work but dereference Uninitialized fw will trigger a NULL 
dereference.

Signed-off-by: Haowen Bai <baihaowen@meizu.com>
---
 drivers/staging/greybus/bootrom.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/greybus/bootrom.c b/drivers/staging/greybus/bootrom.c
index a8efb86..6f3926b 100644
--- a/drivers/staging/greybus/bootrom.c
+++ b/drivers/staging/greybus/bootrom.c
@@ -252,14 +252,6 @@ static int gb_bootrom_get_firmware(struct gb_operation *op)
 	/* Disable timeouts */
 	gb_bootrom_cancel_timeout(bootrom);
 
-	if (op->request->payload_size != sizeof(*firmware_request)) {
-		dev_err(dev, "%s: Illegal size of get firmware request (%zu %zu)\n",
-			__func__, op->request->payload_size,
-			sizeof(*firmware_request));
-		ret = -EINVAL;
-		goto queue_work;
-	}
-
 	mutex_lock(&bootrom->mutex);
 
 	fw = bootrom->fw;
@@ -269,6 +261,15 @@ static int gb_bootrom_get_firmware(struct gb_operation *op)
 		goto unlock;
 	}
 
+	if (op->request->payload_size != sizeof(*firmware_request)) {
+		dev_err(dev, "%s: Illegal size of get firmware request (%zu %zu)\n",
+			__func__, op->request->payload_size,
+			sizeof(*firmware_request));
+		ret = -EINVAL;
+		mutex_unlock(&bootrom->mutex);
+		goto queue_work;
+	}
+
 	firmware_request = op->request->payload;
 	offset = le32_to_cpu(firmware_request->offset);
 	size = le32_to_cpu(firmware_request->size);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] staging: greybus: Fix potential NULL dereference
  2022-03-11  8:35 [PATCH] staging: greybus: Fix potential NULL dereference Haowen Bai
@ 2022-03-11  8:40 ` Viresh Kumar
  2022-03-11  8:50   ` 答复: " 白浩文
  2022-03-11 11:32 ` Dan Carpenter
  1 sibling, 1 reply; 5+ messages in thread
From: Viresh Kumar @ 2022-03-11  8:40 UTC (permalink / raw)
  To: Haowen Bai; +Cc: vireshk, johan, elder, gregkh, linux-staging, linux-kernel

On 11-03-22, 16:35, Haowen Bai wrote:
> Fix following coccicheck warning:
> drivers/staging/greybus/bootrom.c:301:35-39: ERROR: fw is NULL but dereferenced.
> 
> When goto queue_work but dereference Uninitialized fw will trigger a NULL 
> dereference.

Please have a look at earlier attempts like this:

https://lore.kernel.org/all/2015099.xVv48VzNit@linux.local/

-- 
viresh

^ permalink raw reply	[flat|nested] 5+ messages in thread

* 答复: [PATCH] staging: greybus: Fix potential NULL dereference
  2022-03-11  8:40 ` Viresh Kumar
@ 2022-03-11  8:50   ` 白浩文
  0 siblings, 0 replies; 5+ messages in thread
From: 白浩文 @ 2022-03-11  8:50 UTC (permalink / raw)
  To: Viresh Kumar; +Cc: vireshk, johan, elder, gregkh, linux-staging, linux-kernel

Oh, my careless to check code. Thank you for your kindly reminder.
________________________________________
发件人: Viresh Kumar <viresh.kumar@linaro.org>
发送时间: 2022年3月11日 16:40:19
收件人: 白浩文
抄送: vireshk@kernel.org; johan@kernel.org; elder@kernel.org; gregkh@linuxfoundation.org; linux-staging@lists.linux.dev; linux-kernel@vger.kernel.org
主题: Re: [PATCH] staging: greybus: Fix potential NULL dereference

On 11-03-22, 16:35, Haowen Bai wrote:
> Fix following coccicheck warning:
> drivers/staging/greybus/bootrom.c:301:35-39: ERROR: fw is NULL but dereferenced.
>
> When goto queue_work but dereference Uninitialized fw will trigger a NULL
> dereference.

Please have a look at earlier attempts like this:

https://lore.kernel.org/all/2015099.xVv48VzNit@linux.local/

--
viresh

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] staging: greybus: Fix potential NULL dereference
  2022-03-11  8:35 [PATCH] staging: greybus: Fix potential NULL dereference Haowen Bai
  2022-03-11  8:40 ` Viresh Kumar
@ 2022-03-11 11:32 ` Dan Carpenter
  2022-03-14  1:12   ` 答复: " 白浩文
  1 sibling, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2022-03-11 11:32 UTC (permalink / raw)
  To: Haowen Bai; +Cc: vireshk, johan, elder, gregkh, linux-staging, linux-kernel

On Fri, Mar 11, 2022 at 04:35:30PM +0800, Haowen Bai wrote:
> Fix following coccicheck warning:
> drivers/staging/greybus/bootrom.c:301:35-39: ERROR: fw is NULL but dereferenced.
> 
> When goto queue_work but dereference Uninitialized fw will trigger a NULL 
> dereference.
> 
> Signed-off-by: Haowen Bai <baihaowen@meizu.com>

Your patch claims to fix a bug, but the warning is a false positive.
When we "goto queue_work;" then "ret = -EINVAL" so that means that we
will not dereference "fw".

You should ignore false positive warnings.

We would apply the patch only if it made the code more readable but I
do not think that is the case here.  I do not really even see how the
patch silences the false positive warning, but it may do...

Anyway, the point is:  False positive.  Ignore it.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 5+ messages in thread

* 答复: [PATCH] staging: greybus: Fix potential NULL dereference
  2022-03-11 11:32 ` Dan Carpenter
@ 2022-03-14  1:12   ` 白浩文
  0 siblings, 0 replies; 5+ messages in thread
From: 白浩文 @ 2022-03-14  1:12 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: vireshk, johan, elder, gregkh, linux-staging, linux-kernel

Thank you for your suggestion.
________________________________________
发件人: Dan Carpenter <dan.carpenter@oracle.com>
发送时间: 2022年3月11日 19:32:08
收件人: 白浩文
抄送: vireshk@kernel.org; johan@kernel.org; elder@kernel.org; gregkh@linuxfoundation.org; linux-staging@lists.linux.dev; linux-kernel@vger.kernel.org
主题: Re: [PATCH] staging: greybus: Fix potential NULL dereference

On Fri, Mar 11, 2022 at 04:35:30PM +0800, Haowen Bai wrote:
> Fix following coccicheck warning:
> drivers/staging/greybus/bootrom.c:301:35-39: ERROR: fw is NULL but dereferenced.
>
> When goto queue_work but dereference Uninitialized fw will trigger a NULL
> dereference.
>
> Signed-off-by: Haowen Bai <baihaowen@meizu.com>

Your patch claims to fix a bug, but the warning is a false positive.
When we "goto queue_work;" then "ret = -EINVAL" so that means that we
will not dereference "fw".

You should ignore false positive warnings.

We would apply the patch only if it made the code more readable but I
do not think that is the case here.  I do not really even see how the
patch silences the false positive warning, but it may do...

Anyway, the point is:  False positive.  Ignore it.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-03-14  1:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-11  8:35 [PATCH] staging: greybus: Fix potential NULL dereference Haowen Bai
2022-03-11  8:40 ` Viresh Kumar
2022-03-11  8:50   ` 答复: " 白浩文
2022-03-11 11:32 ` Dan Carpenter
2022-03-14  1:12   ` 答复: " 白浩文

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).