mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniil Dulov <D.Dulov@aladdin.ru>
To: Vadim Pasternak <vadimp@nvidia.com>, Hans de Goede <hdegoede@redhat.com>
Cc: Mark Gross <mgross@linux.intel.com>,
	Andy Shevchenko <andy@infradead.org>,
	Darren Hart <dvhart@infradead.org>,
	"platform-driver-x86@vger.kernel.org"
	<platform-driver-x86@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"lvc-project@linuxtesting.org" <lvc-project@linuxtesting.org>
Subject: RE: [PATCH] platform/mellanox: mlxreg-hotplug: Check pointer for NULL before dereferencing it
Date: Mon, 4 Mar 2024 11:43:38 +0000	[thread overview]
Message-ID: <e34edced65e747c5870ee439e3c84457@aladdin.ru> (raw)
In-Reply-To: <BN9PR12MB538106C733D231B73FC1C1AAAF5A2@BN9PR12MB5381.namprd12.prod.outlook.com>

Hello!

I suppose there is no sense to produce dev_err() inside
mlxreg_hotplug_work_helper() since item is dereferenced twice
before we call this function. Should we produce dev_err()
inside the loop in mlxreg_hotplug_work_handler() instead?

-----Original Message-----
From: Vadim Pasternak [mailto:vadimp@nvidia.com] 
Sent: Monday, February 26, 2024 6:15 PM
To: Daniil Dulov <D.Dulov@aladdin.ru>; Hans de Goede <hdegoede@redhat.com>
Cc: Mark Gross <mgross@linux.intel.com>; Andy Shevchenko <andy@infradead.org>; Darren Hart <dvhart@infradead.org>; platform-driver-x86@vger.kernel.org; linux-kernel@vger.kernel.org; lvc-project@linuxtesting.org
Subject: RE: [PATCH] platform/mellanox: mlxreg-hotplug: Check pointer for NULL before dereferencing it



> -----Original Message-----
> From: Daniil Dulov <d.dulov@aladdin.ru>
> Sent: Monday, 26 February 2024 16:55
> To: Hans de Goede <hdegoede@redhat.com>
> Cc: Daniil Dulov <d.dulov@aladdin.ru>; Mark Gross
> <mgross@linux.intel.com>; Andy Shevchenko <andy@infradead.org>; Darren
> Hart <dvhart@infradead.org>; Vadim Pasternak <vadimp@nvidia.com>;
> platform-driver-x86@vger.kernel.org; linux-kernel@vger.kernel.org; lvc-
> project@linuxtesting.org
> Subject: [PATCH] platform/mellanox: mlxreg-hotplug: Check pointer for NULL
> before dereferencing it
> 
> mlxreg_hotplug_work_helper() implies that item can be NULL. There is a
> sanity check that checks item for NULL and then dereferences it.
> 
> Even though, the comment before sanity check says that it can only happen if
> some piece of hardware is broken, but in this case it will lead to NULL-pointer
> dereference before the function is even called, so let's check it before
> dereferencing.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Fixes: c6acad68eb2d ("platform/mellanox: mlxreg-hotplug: Modify to use a
> regmap interface")
> Signed-off-by: Daniil Dulov <d.dulov@aladdin.ru>
> ---
>  drivers/platform/mellanox/mlxreg-hotplug.c | 16 +---------------
>  1 file changed, 1 insertion(+), 15 deletions(-)
> 
> diff --git a/drivers/platform/mellanox/mlxreg-hotplug.c
> b/drivers/platform/mellanox/mlxreg-hotplug.c
> index 5c022b258f91..524121b9f070 100644
> --- a/drivers/platform/mellanox/mlxreg-hotplug.c
> +++ b/drivers/platform/mellanox/mlxreg-hotplug.c
> @@ -348,20 +348,6 @@ mlxreg_hotplug_work_helper(struct
> mlxreg_hotplug_priv_data *priv,
>  	u32 regval, bit;
>  	int ret;
> 
> -	/*
> -	 * Validate if item related to received signal type is valid.
> -	 * It should never happen, excepted the situation when some
> -	 * piece of hardware is broken. In such situation just produce
> -	 * error message and return. Caller must continue to handle the
> -	 * signals from other devices if any.
> -	 */
> -	if (unlikely(!item)) {
> -		dev_err(priv->dev, "False signal: at offset:mask
> 0x%02x:0x%02x.\n",
> -			item->reg, item->mask);
> -
> -		return;
> -	}

It would be enough just to produce dev_err(priv->dev, "False signal\n");
And return.

> -
>  	/* Mask event. */
>  	ret = regmap_write(priv->regmap, item->reg +
> MLXREG_HOTPLUG_MASK_OFF,
>  			   0);
> @@ -556,7 +542,7 @@ static void mlxreg_hotplug_work_handler(struct
> work_struct *work)
> 
>  	/* Handle topology and health configuration changes. */
>  	for (i = 0; i < pdata->counter; i++, item++) {
> -		if (aggr_asserted & item->aggr_mask) {
> +		if (item && (aggr_asserted & item->aggr_mask)) {
>  			if (item->health)
>  				mlxreg_hotplug_health_work_helper(priv,
> item);
>  			else
> --
> 2.25.1


  reply	other threads:[~2024-03-04 11:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-26 14:54 Daniil Dulov
2024-02-26 15:15 ` Vadim Pasternak
2024-03-04 11:43   ` Daniil Dulov [this message]
2024-03-04 21:26     ` Vadim Pasternak
2024-03-06 15:38       ` [PATCH] platform/mellanox: mlxreg-hotplug: Remove redundant NULL-check Daniil Dulov
2024-03-06 16:01         ` Vadim Pasternak
2024-03-07 10:09         ` Ilpo Järvinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e34edced65e747c5870ee439e3c84457@aladdin.ru \
    --to=d.dulov@aladdin.ru \
    --cc=andy@infradead.org \
    --cc=dvhart@infradead.org \
    --cc=hdegoede@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=mgross@linux.intel.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=vadimp@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®