[PATCH] platform/mellanox: mlxreg-lc: Check before variable dereferenced

9 views
Skip to first unread message

Yu Sun

unread,
Nov 30, 2023, 4:45:47 AM11/30/23
to Hans de Goede, Ilpo Järvinen, Mark Gross, Vadim Pasternak, hust-os-ker...@googlegroups.com, Yu Sun, Dongliang Mu, Dan Carpenter, platform-...@vger.kernel.org, linux-...@vger.kernel.org
there is a warning saying variable dereferenced before
check 'data->notifier' in line 828.
add "for(data->notifier)" before variable deferenced.

Signed-off-by: Yu Sun <u2021...@hust.edu.cn>
Reviewed-by: Dongliang Mu <dz...@hust.edu.cn>
Reviewed-by: Dan Carpenter <err...@gmail.com>
---
drivers/platform/mellanox/mlxreg-lc.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/platform/mellanox/mlxreg-lc.c b/drivers/platform/mellanox/mlxreg-lc.c
index 43d119e3a473..e92add40750b 100644
--- a/drivers/platform/mellanox/mlxreg-lc.c
+++ b/drivers/platform/mellanox/mlxreg-lc.c
@@ -824,9 +824,12 @@ static int mlxreg_lc_probe(struct platform_device *pdev)
return -ENOMEM;

mutex_init(&mlxreg_lc->lock);
- /* Set event notification callback. */
- data->notifier->user_handler = mlxreg_lc_event_handler;
- data->notifier->handle = mlxreg_lc;
+
+ if (data->notifier) {
+ /* Set event notification callback. */
+ data->notifier->user_handler = mlxreg_lc_event_handler;
+ data->notifier->handle = mlxreg_lc;
+ }

data->hpdev.adapter = i2c_get_adapter(data->hpdev.nr);
if (!data->hpdev.adapter) {
--
2.42.0

Dan Carpenter

unread,
Nov 30, 2023, 6:47:35 AM11/30/23
to Yu Sun, Hans de Goede, Ilpo Järvinen, Mark Gross, Vadim Pasternak, hust-os-ker...@googlegroups.com, Dongliang Mu, Dan Carpenter, platform-...@vger.kernel.org, linux-...@vger.kernel.org
On Thu, Nov 30, 2023 at 05:44:07PM +0800, Yu Sun wrote:
> there is a warning saying variable dereferenced before
> check 'data->notifier' in line 828.
> add "for(data->notifier)" before variable deferenced.
^^^
Should have been "if (data->notifier)".

>
> Signed-off-by: Yu Sun <u2021...@hust.edu.cn>
> Reviewed-by: Dongliang Mu <dz...@hust.edu.cn>
> Reviewed-by: Dan Carpenter <err...@gmail.com>

I didn't really explicitly give a Reviewed-by tag for this patch.
https://groups.google.com/g/hust-os-kernel-patches/c/c5hUaYIDcII/m/h4aFS7PkCQAJ
I also said that I thought it looked correct but that it needed a Fixes:
tag however the Fixes tag I suggested was wrong.

Looking at it now, the correct Fixes tag would be:
Fixes: 1c8ee06b637f ("platform/mellanox: Remove unnecessary code")

That commit says that the NULL check is not required. So now I'm
confused. On the one hand, the impulse is to trust the maintainer, but
on the other hand my review suggested that the NULL check might be
required.

regards,
dan carpenter


Vadim Pasternak

unread,
Nov 30, 2023, 11:24:31 AM11/30/23
to Dan Carpenter, Yu Sun, Hans de Goede, Ilpo Järvinen, Mark Gross, hust-os-ker...@googlegroups.com, Dongliang Mu, Dan Carpenter, platform-...@vger.kernel.org, linux-...@vger.kernel.org
Hi Dan,

> -----Original Message-----
> From: Dan Carpenter <dan.ca...@linaro.org>
> Sent: Thursday, 30 November 2023 13:47
> To: Yu Sun <u2021...@hust.edu.cn>
> Cc: Hans de Goede <hdeg...@redhat.com>; Ilpo Järvinen
> <ilpo.j...@linux.intel.com>; Mark Gross <mark...@kernel.org>; Vadim
> Pasternak <vad...@nvidia.com>; hust-os-kernel-
> pat...@googlegroups.com; Dongliang Mu <dz...@hust.edu.cn>; Dan
> Carpenter <err...@gmail.com>; platform-...@vger.kernel.org; linux-
> ker...@vger.kernel.org
> Subject: Re: [PATCH] platform/mellanox: mlxreg-lc: Check before variable
> dereferenced
Yes, it indeed required.
My mistake.

Thank you for your comments.

>
> regards,
> dan carpenter
>

Hans de Goede

unread,
Dec 2, 2023, 6:39:39 AM12/2/23
to Vadim Pasternak, Dan Carpenter, Yu Sun, Ilpo Järvinen, Mark Gross, hust-os-ker...@googlegroups.com, Dongliang Mu, Dan Carpenter, platform-...@vger.kernel.org, linux-...@vger.kernel.org
Hi,
Ok, so we are going to need a v2 of this addressing Dan's remarks
about the commit message.

Yu Sun, can you please submit a new version addressing
Dan's comments on the commit message ?

Regards,

Hans


孙宇

unread,
Dec 14, 2023, 11:26:20 PM12/14/23
to Hans de Goede, Vadim Pasternak, Dan Carpenter, Ilpo Järvinen, Mark Gross, hust-os-ker...@googlegroups.com, Dongliang Mu, Dan Carpenter, platform-...@vger.kernel.org, linux-...@vger.kernel.org
Thank you for your suggestions,I will submit a V2 patch soon.




发件人:"Hans de Goede" <hdeg...@redhat.com>
发送日期:2023-12-02 19:39:33
收件人:"Vadim Pasternak" <vad...@nvidia.com>, "Dan Carpenter" <dan.ca...@linaro.org>, "Yu Sun" <u2021...@hust.edu.cn>
抄送人:
主 题:Re: [PATCH] platform/mellanox: mlxreg-lc: Check before variable dereferenced

Yalong Zou

unread,
Dec 15, 2023, 12:39:07 PM12/15/23
to Yu Sun, HUST OS Kernel Contribution
On Thu, Nov 30, 2023 at 05:44:07PM +0800, Yu Sun wrote:
>
> there is a warning saying variable dereferenced before
> check 'data->notifier' in line 828.
> add "for(data->notifier)" before variable deferenced.

Remember this, 'if (data->notifier)'

>

Add a fixes tag here. Dan has provided a correct tag for you, and you
can paste it here.

To find this tag, run command:

$ git blame drivers/platform/mellanox/mlxreg-lc.c -L 828,829

and you will get the result:

1c8ee06b637f0 (Vadim Pasternak 2022-08-23 23:19:36 +0300 828) data->notifier->user_handler = mlxreg_lc_event_handler;
1c8ee06b637f0 (Vadim Pasternak 2022-08-23 23:19:36 +0300 829) data->notifier->handle = mlxreg_lc;

So '1c8ee06b637f0' is the commit hash you want, and then:

$ git log --pretty="Fixes: %h (\"%s\")" 1c8ee06b637f0 -1

here we get the tag you need:

Fixes: 1c8ee06b637f ("platform/mellanox: Remove unnecessary code")

You can refer to the link below:
https://ixy0caf7465.feishu.cn/wiki/K9zVw6nGAicMRCkaM1fcWx3Onhh#GKiCdgWKuoCwq0xikifcbDaenFc

> Signed-off-by: Yu Sun <u2021...@hust.edu.cn>
> Reviewed-by: Dongliang Mu <dz...@hust.edu.cn>
> Reviewed-by: Dan Carpenter <err...@gmail.com>

You need to delete the above line according to Dan. Please notice that
we only add the 'Reviewed-by' tag only if the reviewer reply to your
patch and contains the tag.

Besides, Dan's commonly used email address is dan.ca...@linaro.org now :)

You can refer to the link below for details:
https://ixy0caf7465.feishu.cn/wiki/K9zVw6nGAicMRCkaM1fcWx3Onhh#T2Med2qQmoIWcsxqmOichbAIncc

> ---
> drivers/platform/mellanox/mlxreg-lc.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/platform/mellanox/mlxreg-lc.c b/drivers/platform/mellanox/mlxreg-lc.c
> index 43d119e3a473..e92add40750b 100644
> --- a/drivers/platform/mellanox/mlxreg-lc.c
> +++ b/drivers/platform/mellanox/mlxreg-lc.c
> @@ -824,9 +824,12 @@ static int mlxreg_lc_probe(struct platform_device *pdev)
> return -ENOMEM;
>
> mutex_init(&mlxreg_lc->lock);
> - /* Set event notification callback. */
> - data->notifier->user_handler = mlxreg_lc_event_handler;
> - data->notifier->handle = mlxreg_lc;
> +
> + if (data->notifier) {
> + /* Set event notification callback. */
> + data->notifier->user_handler = mlxreg_lc_event_handler;
> + data->notifier->handle = mlxreg_lc;
> + }
>
> data->hpdev.adapter = i2c_get_adapter(data->hpdev.nr);
> if (!data->hpdev.adapter) {
> --
> 2.42.0

The author of the previous commit has confirmed that we need a NULL
check here. So just fix up this patch and send a v2 version. If you are
not sure, you can send the patch to our private mailing list first.

--
Appreciate for your effors to our contribution group!
Regards,

Yalong Zou
HUST CSE

Reply all
Reply to author
Forward
0 new messages