public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Ioana Ciornei <ioana.ciornei@nxp.com>
To: Alex Dewar <alex.dewar90@gmail.com>
Cc: Ioana Ciocoi Radulescu <ruxandra.radulescu@nxp.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] dpaa2-mac: Fix potential null pointer dereference
Date: Sun, 27 Sep 2020 13:59:52 +0000	[thread overview]
Message-ID: <20200927135950.cy536vnvrae6h2ne@skbuf> (raw)
In-Reply-To: <20200927133119.586083-1-alex.dewar90@gmail.com>

On Sun, Sep 27, 2020 at 02:31:20PM +0100, Alex Dewar wrote:
> In dpaa2_pcs_destroy, variable pcs is dereference before it is
> null-checked. Fix this.
> 
> Addresses-Coverity: CID 1497159: Null pointer dereferences (REVERSE_INULL)
> Signed-off-by: Alex Dewar <alex.dewar90@gmail.com>
> ---
>  drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c
> index 6ff64dd1cf27..09bf4fec1172 100644
> --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c
> +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c
> @@ -291,11 +291,10 @@ static int dpaa2_pcs_create(struct dpaa2_mac *mac,
>  static void dpaa2_pcs_destroy(struct dpaa2_mac *mac)
>  {
>  	struct lynx_pcs *pcs = mac->pcs;
> -	struct device *dev = &pcs->mdio->dev;
>  
>  	if (pcs) {
>  		lynx_pcs_destroy(pcs);
> -		put_device(dev);
> +		put_device(&pcs->mdio->dev);
>  		mac->pcs = NULL;
>  	}
>  }

This would introduce another problem because you would access an already
freed pcs. Maybe just move the declaration and initialization of dev
inside the if statement.

Thanks, Ioana

      reply	other threads:[~2020-09-27 13:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-27 13:31 [PATCH] dpaa2-mac: Fix potential null pointer dereference Alex Dewar
2020-09-27 13:59 ` Ioana Ciornei [this message]

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=20200927135950.cy536vnvrae6h2ne@skbuf \
    --to=ioana.ciornei@nxp.com \
    --cc=alex.dewar90@gmail.com \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=ruxandra.radulescu@nxp.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