From mboxrd@z Thu Jan 1 00:00:00 1970 From: Simon Glass Date: Mon, 4 May 2020 08:17:47 -0600 Subject: [PATCH 1/4] sata: ahsata: Fix resource leak In-Reply-To: <20200503142703.14903-1-peng.fan@nxp.com> References: <20200503142703.14903-1-peng.fan@nxp.com> Message-ID: List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Sun, 3 May 2020 at 08:04, Peng Fan wrote: > > From: Ye Li > > Fix coverity issue CID 3606684: Resource leak (RESOURCE_LEAK) > leaked_storage: Variable uc_priv going out of scope leaks the storage it points to > > Signed-off-by: Ye Li > Signed-off-by: Peng Fan > --- > drivers/ata/dwc_ahsata.c | 5 +++++ > 1 file changed, 5 insertions(+) Reviewed-by: Simon Glass > > diff --git a/drivers/ata/dwc_ahsata.c b/drivers/ata/dwc_ahsata.c > index c2e28fe518..a775214792 100644 > --- a/drivers/ata/dwc_ahsata.c > +++ b/drivers/ata/dwc_ahsata.c > @@ -847,6 +847,9 @@ static int ahci_init_one(int pdev) > struct ahci_uc_priv *uc_priv = NULL; > > uc_priv = malloc(sizeof(struct ahci_uc_priv)); > + if (!uc_priv) > + return -ENOMEM; > + > memset(uc_priv, 0, sizeof(struct ahci_uc_priv)); > uc_priv->dev = pdev; > > @@ -871,6 +874,8 @@ static int ahci_init_one(int pdev) > return 0; > > err_out: > + if (uc_priv) > + free(uc_priv); Seems like you can avoid the if() since it is always allocated at this point? The migration date for SATA was over 6 months ago so really this code should not be used at this point. Regards, Simon