Message ID | 20230607070255.2013980-1-saikrishnag@marvell.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp69733vqr; Wed, 7 Jun 2023 00:23:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4BSs521DX/CqciwbasoB6xR+ZwGifIvpJRF5kjCHPFe40H8OqPGeqOJFZetOTejy9myTOh X-Received: by 2002:a05:6359:2a0:b0:129:7bf:eeca with SMTP id ek32-20020a05635902a000b0012907bfeecamr1474453rwb.21.1686122637042; Wed, 07 Jun 2023 00:23:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686122637; cv=none; d=google.com; s=arc-20160816; b=lbiI7mmkQO7Ab+8LOzJDFR2ENMbI0pRBJgAaMpHY0JZYcb0GF/0Yvpq1FbtzN/CVDd g/vW4c8LH0zPfeu7MxrhuzpOLKYpQp186ZsbRc/AX/IT5WmP8DDkXDWjqLJHLIeA16Gh bnkcSkWJuSfDyk9238qPpxus75PyiB227BDOjh0jvlzXhR8aEY5kIDHegVFprYcvAvv7 DJlovwld2f/DaMy5wegiBvBrhPzUpASc1b2LcGNdsId2iLrKAALX+1sVzOpbg0q+KzUa W9LB7ZbuBiNzHv6QNK2rNXzuFgpIUEaLUv1GK0zNLTnJyuYOKBgJs0Q8Fy7+KroM73vj fU6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=k923a7Oxn1k2haeRkq4asJ9KrNimQZa4Ue+wkrhnX9g=; b=wAf+W6uYwOr5iZiqvgX3n7a1LJg9bBLSPuswag+xXN0uZqH6VBsjDcNaC1PZ7nIxAQ 0y/1Yby1iqVOq8Or2UzGaz1uuBqdlB8HWyTq9CQSd8eVZ9Ajzyss5jTdgmiX/i0HaSKS uoC/yNsjkCD3alo9x7PiEtrlXsKruYGTUJ+VnhpA+P5iURmeYYksw0p9V3928yyhrrNh qBNynBEK6l1FNKZb3j90fe14515fkDb964aJfPai4SkFErS6jQyTQUOKb21ZsndwqpQl HDkLCvQxK/htt5YKohkKObmK+d30D3sGlIMSNCfNplJnikKBriAtVXTHp2iACYkJUdeM 0L9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@marvell.com header.s=pfpt0220 header.b=XeAGaidR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=marvell.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y186-20020a638ac3000000b0054507258ce0si251463pgd.234.2023.06.07.00.23.44; Wed, 07 Jun 2023 00:23:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@marvell.com header.s=pfpt0220 header.b=XeAGaidR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=marvell.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238606AbjFGHDY (ORCPT <rfc822;literming00@gmail.com> + 99 others); Wed, 7 Jun 2023 03:03:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238205AbjFGHDV (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 7 Jun 2023 03:03:21 -0400 Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6ED321732; Wed, 7 Jun 2023 00:03:20 -0700 (PDT) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3575KDC2022645; Wed, 7 Jun 2023 00:03:06 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=k923a7Oxn1k2haeRkq4asJ9KrNimQZa4Ue+wkrhnX9g=; b=XeAGaidRrB/iL3X2hENXzlCCevc93bUGD0ulGN9z5QFWYz3qUf7K31sqDfh7Fy2z9YzZ 9kyvy+AW3B+1qxcCCnbOql3gnwVU4OvwwBnlZMdvXYoC8VYEZOxChTQvQPqqMqAK9acC wuTF3ZCTMqTVY7LnGXdqkprf19t7mzkl03ds99uBLGZOarg2RGhvOFkY1QnovttNxBg/ W1ebfx30wWu7ZtG4TdPVYWNaYuQIrUSg+FDMKUidH14HHjhQHdRGuptj5hEopASBqIKa +ntYcv2tJSxY8vVeLpJYFZD1JF4femYaYX9eyVuj/QKY1fwbj0x10mh3rJir2a2h25NF Ow== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3r2a759tra-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 07 Jun 2023 00:03:05 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Wed, 7 Jun 2023 00:03:03 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Wed, 7 Jun 2023 00:03:03 -0700 Received: from hyd1425.marvell.com (unknown [10.29.37.83]) by maili.marvell.com (Postfix) with ESMTP id 03AC53F708E; Wed, 7 Jun 2023 00:03:00 -0700 (PDT) From: Sai Krishna <saikrishnag@marvell.com> To: <davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>, <pabeni@redhat.com>, <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <sgoutham@marvell.com>, <dan.carpenter@linaro.org> CC: Sai Krishna <saikrishnag@marvell.com>, Naveen Mamindlapalli <naveenm@marvell.com> Subject: [net PATCH] octeontx2-af: Fix pointer dereference before sanity check Date: Wed, 7 Jun 2023 12:32:55 +0530 Message-ID: <20230607070255.2013980-1-saikrishnag@marvell.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: wMSWW6VGaA-pXum6hlxiUEb3zaKmJBgv X-Proofpoint-GUID: wMSWW6VGaA-pXum6hlxiUEb3zaKmJBgv X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-07_04,2023-06-06_02,2023-05-22_02 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768027730270332438?= X-GMAIL-MSGID: =?utf-8?q?1768027730270332438?= |
Series |
[net] octeontx2-af: Fix pointer dereference before sanity check
|
|
Commit Message
Sai Krishna Gajula
June 7, 2023, 7:02 a.m. UTC
PTP pointer is being dereferenced before NULL, error check. Fixed the same to avoid NULL dereference and smatch checker warning. Fixes: 2ef4e45d99b1 ("octeontx2-af: Add PTP PPS Errata workaround on CN10K silicon") Signed-off-by: Sai Krishna <saikrishnag@marvell.com> Signed-off-by: Naveen Mamindlapalli <naveenm@marvell.com> --- drivers/net/ethernet/marvell/octeontx2/af/ptp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Comments
On Wed, Jun 07, 2023 at 12:32:55PM +0530, Sai Krishna wrote: > PTP pointer is being dereferenced before NULL, error check. > Fixed the same to avoid NULL dereference and smatch checker warning. please use imperative mood, you could say: Move validation of ptp pointer before its usage > > Fixes: 2ef4e45d99b1 ("octeontx2-af: Add PTP PPS Errata workaround on CN10K silicon") > Signed-off-by: Sai Krishna <saikrishnag@marvell.com> > Signed-off-by: Naveen Mamindlapalli <naveenm@marvell.com> Reviewed-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com> > --- > drivers/net/ethernet/marvell/octeontx2/af/ptp.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/net/ethernet/marvell/octeontx2/af/ptp.c b/drivers/net/ethernet/marvell/octeontx2/af/ptp.c > index 3411e2e47d46..6a7dfb181fa8 100644 > --- a/drivers/net/ethernet/marvell/octeontx2/af/ptp.c > +++ b/drivers/net/ethernet/marvell/octeontx2/af/ptp.c > @@ -449,12 +449,12 @@ static void ptp_remove(struct pci_dev *pdev) > struct ptp *ptp = pci_get_drvdata(pdev); > u64 clock_cfg; > > - if (cn10k_ptp_errata(ptp) && hrtimer_active(&ptp->hrtimer)) > - hrtimer_cancel(&ptp->hrtimer); > - > if (IS_ERR_OR_NULL(ptp)) > return; > > + if (cn10k_ptp_errata(ptp) && hrtimer_active(&ptp->hrtimer)) > + hrtimer_cancel(&ptp->hrtimer); > + > /* Disable PTP clock */ > clock_cfg = readq(ptp->reg_base + PTP_CLOCK_CFG); > clock_cfg &= ~PTP_CLOCK_CFG_PTP_EN; i wonder if ptp_remove() would be able to free the struct ptp that ptp_probe() allocated - then you wouldn't have to use devm_kzalloc(). > -- > 2.25.1 > >
> -----Original Message----- > From: Maciej Fijalkowski <maciej.fijalkowski@intel.com> > Sent: Wednesday, June 7, 2023 5:17 PM > To: Sai Krishna Gajula <saikrishnag@marvell.com> > Cc: davem@davemloft.net; edumazet@google.com; kuba@kernel.org; > pabeni@redhat.com; netdev@vger.kernel.org; linux- > kernel@vger.kernel.org; Sunil Kovvuri Goutham <sgoutham@marvell.com>; > dan.carpenter@linaro.org; Naveen Mamindlapalli <naveenm@marvell.com> > Subject: Re: [net PATCH] octeontx2-af: Fix pointer dereference before > sanity check > > On Wed, Jun 07, 2023 at 12:32:55PM +0530, Sai Krishna wrote: > > PTP pointer is being dereferenced before NULL, error check. > > Fixed the same to avoid NULL dereference and smatch checker warning. > > please use imperative mood, you could say: > Move validation of ptp pointer before its usage > I will change in V2 patch. > > > > Fixes: 2ef4e45d99b1 ("octeontx2-af: Add PTP PPS Errata workaround on > CN10K silicon") > > Signed-off-by: Sai Krishna <saikrishnag@marvell.com> > > Signed-off-by: Naveen Mamindlapalli <naveenm@marvell.com> > > Reviewed-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com> > > > --- > > drivers/net/ethernet/marvell/octeontx2/af/ptp.c | 6 +++--- > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/net/ethernet/marvell/octeontx2/af/ptp.c > b/drivers/net/ethernet/marvell/octeontx2/af/ptp.c > > index 3411e2e47d46..6a7dfb181fa8 100644 > > --- a/drivers/net/ethernet/marvell/octeontx2/af/ptp.c > > +++ b/drivers/net/ethernet/marvell/octeontx2/af/ptp.c > > @@ -449,12 +449,12 @@ static void ptp_remove(struct pci_dev *pdev) > > struct ptp *ptp = pci_get_drvdata(pdev); > > u64 clock_cfg; > > > > - if (cn10k_ptp_errata(ptp) && hrtimer_active(&ptp->hrtimer)) > > - hrtimer_cancel(&ptp->hrtimer); > > - > > if (IS_ERR_OR_NULL(ptp)) > > return; > > > > + if (cn10k_ptp_errata(ptp) && hrtimer_active(&ptp->hrtimer)) > > + hrtimer_cancel(&ptp->hrtimer); > > + > > /* Disable PTP clock */ > > clock_cfg = readq(ptp->reg_base + PTP_CLOCK_CFG); > > clock_cfg &= ~PTP_CLOCK_CFG_PTP_EN; > > i wonder if ptp_remove() would be able to free the struct ptp that > ptp_probe() allocated - then you wouldn't have to use devm_kzalloc(). > We intend to use devm_kzalloc() so that we do not need to call kfree in the remove function. Please let us know why you prefer to manually free the resource. Thanks, Sai > > -- > > 2.25.1 > > > >
On Wed, Jun 07, 2023 at 12:04:40PM +0000, Sai Krishna Gajula wrote: > > > -----Original Message----- > > From: Maciej Fijalkowski <maciej.fijalkowski@intel.com> > > Sent: Wednesday, June 7, 2023 5:17 PM > > To: Sai Krishna Gajula <saikrishnag@marvell.com> > > Cc: davem@davemloft.net; edumazet@google.com; kuba@kernel.org; > > pabeni@redhat.com; netdev@vger.kernel.org; linux- > > kernel@vger.kernel.org; Sunil Kovvuri Goutham <sgoutham@marvell.com>; > > dan.carpenter@linaro.org; Naveen Mamindlapalli <naveenm@marvell.com> > > Subject: Re: [net PATCH] octeontx2-af: Fix pointer dereference before > > sanity check > > > > On Wed, Jun 07, 2023 at 12:32:55PM +0530, Sai Krishna wrote: > > > PTP pointer is being dereferenced before NULL, error check. > > > Fixed the same to avoid NULL dereference and smatch checker warning. > > > > please use imperative mood, you could say: > > Move validation of ptp pointer before its usage > > > I will change in V2 patch. > > > > > > > Fixes: 2ef4e45d99b1 ("octeontx2-af: Add PTP PPS Errata workaround on > > CN10K silicon") > > > Signed-off-by: Sai Krishna <saikrishnag@marvell.com> > > > Signed-off-by: Naveen Mamindlapalli <naveenm@marvell.com> > > > > Reviewed-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com> > > > > > --- > > > drivers/net/ethernet/marvell/octeontx2/af/ptp.c | 6 +++--- > > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > > > diff --git a/drivers/net/ethernet/marvell/octeontx2/af/ptp.c > > b/drivers/net/ethernet/marvell/octeontx2/af/ptp.c > > > index 3411e2e47d46..6a7dfb181fa8 100644 > > > --- a/drivers/net/ethernet/marvell/octeontx2/af/ptp.c > > > +++ b/drivers/net/ethernet/marvell/octeontx2/af/ptp.c > > > @@ -449,12 +449,12 @@ static void ptp_remove(struct pci_dev *pdev) > > > struct ptp *ptp = pci_get_drvdata(pdev); > > > u64 clock_cfg; > > > > > > - if (cn10k_ptp_errata(ptp) && hrtimer_active(&ptp->hrtimer)) > > > - hrtimer_cancel(&ptp->hrtimer); > > > - > > > if (IS_ERR_OR_NULL(ptp)) > > > return; > > > > > > + if (cn10k_ptp_errata(ptp) && hrtimer_active(&ptp->hrtimer)) > > > + hrtimer_cancel(&ptp->hrtimer); > > > + > > > /* Disable PTP clock */ > > > clock_cfg = readq(ptp->reg_base + PTP_CLOCK_CFG); > > > clock_cfg &= ~PTP_CLOCK_CFG_PTP_EN; > > > > i wonder if ptp_remove() would be able to free the struct ptp that > > ptp_probe() allocated - then you wouldn't have to use devm_kzalloc(). > > > We intend to use devm_kzalloc() so that we do not need to call kfree in > the remove function. Please let us know why you prefer to manually free > the resource. I just don't think this is really necessary as this object's lifetime scope is clearly defined, i am in the rush now but i can try to come up with further arguments later on if needed. > > Thanks, > Sai > > > -- > > > 2.25.1 > > > > > >
diff --git a/drivers/net/ethernet/marvell/octeontx2/af/ptp.c b/drivers/net/ethernet/marvell/octeontx2/af/ptp.c index 3411e2e47d46..6a7dfb181fa8 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/ptp.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/ptp.c @@ -449,12 +449,12 @@ static void ptp_remove(struct pci_dev *pdev) struct ptp *ptp = pci_get_drvdata(pdev); u64 clock_cfg; - if (cn10k_ptp_errata(ptp) && hrtimer_active(&ptp->hrtimer)) - hrtimer_cancel(&ptp->hrtimer); - if (IS_ERR_OR_NULL(ptp)) return; + if (cn10k_ptp_errata(ptp) && hrtimer_active(&ptp->hrtimer)) + hrtimer_cancel(&ptp->hrtimer); + /* Disable PTP clock */ clock_cfg = readq(ptp->reg_base + PTP_CLOCK_CFG); clock_cfg &= ~PTP_CLOCK_CFG_PTP_EN;