Message ID | 20240211150824.3947-1-d.dulov@aladdin.ru |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-60823-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp1969147dyd; Sun, 11 Feb 2024 07:10:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IGgKpUqfKa1dYseHOmyDyFqEH/CrQnR9SAPDUCjNqRC9c5M494lrKOdcAOOYb8Mj6ZUpbuV X-Received: by 2002:a17:907:7d9f:b0:a38:567a:6574 with SMTP id oz31-20020a1709077d9f00b00a38567a6574mr7032513ejc.5.1707664252309; Sun, 11 Feb 2024 07:10:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707664252; cv=pass; d=google.com; s=arc-20160816; b=rKQKROzlAH6uwZ6VF6E/JchNfYCUvA8yZwWQ/wHd9ofeIs7rOh6CWFFZD+kRpKyjve mSgmjddhD+jkkFOBVxAkj2IEf4hwoamkG64s21eG8i4d7CFVEGvEUOaqirpeTt/ISwr2 ZEt+dn3a319iW1g9y4Ydz9Eu7sa7YDTczzQqIt9R2ZWkknH88TKFCLgj1AeghOD3svOC NR6+LLcQB1e+PUaPEDgKKjlcWNC6a/1/IbVaaZlH4KeIDcryCvMFC8E4hwGBOmA27NOk fW4rI3J8jvPQm4PsSjZ2Lv2BAd3xij+/KbVuS/8r4BIkOAFFYV+9HbsF76hMpnEmcDwR Y6dQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=0O2hKbD7cQmxHYdkkdX6GGn7xZswdwjGGX1DQCekUIw=; fh=AseSFVOfXS1LGltDMceHkfaA6dKn9arjDYpznq2nKYQ=; b=hZXhFSImFIzdfyuYXSE/Rthw2o1TGAJDD7mBfW1Bk0W7p1dkzfoMsXfkjGb3XpNKCF Jd7bOQj1lrxG8zw26SyApP+viotMLefVH6+88DhtGYOG/bRmTtBBJJY6zlecZRd45pMj K4wzhsskpUsrXTeHpf0T917u7RbT/0EABniUH95MV/X0YpwvgdGRBPpkrSjEt/hPrWxE +fsX88NYWpVfOOxb3IlZgNa25fXV7I1CJlPWlMPVwI4CUnIUb9cPMJtuShd/uL+nyytU PB0gOYBLq6rwRifiGsChU2/SUgf9ESvq6Yo/p31iKM3Dlhtong4xVpg7p9IgbbgU6bRX h5KQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=aladdin.ru dmarc=pass fromdomain=aladdin.ru); spf=pass (google.com: domain of linux-kernel+bounces-60823-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60823-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aladdin.ru X-Forwarded-Encrypted: i=2; AJvYcCVyXU5UEbGLDHWCPqKyl4t2gmrqM2biZHC0MKQCTevm5HGOLrxRlj3JaHKddYBgHoV06dRe+QM/0fwqLJdwivCqKtpUQw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id f27-20020a170906139b00b00a3c9aacbae5si138006ejc.941.2024.02.11.07.10.52 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 07:10:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60823-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=aladdin.ru dmarc=pass fromdomain=aladdin.ru); spf=pass (google.com: domain of linux-kernel+bounces-60823-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60823-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aladdin.ru Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E786E1F21DA0 for <ouuuleilei@gmail.com>; Sun, 11 Feb 2024 15:10:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 927745EE6D; Sun, 11 Feb 2024 15:08:35 +0000 (UTC) Received: from mail-out.aladdin-rd.ru (mail-out.aladdin-rd.ru [91.199.251.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 40E155B695; Sun, 11 Feb 2024 15:08:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.199.251.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707664114; cv=none; b=JGXrq6RXnNcztDo2+LCkF2EB/BT0OnCvs8WTTyUAQ1OSHy+KWHJaeq60XMC+CISBavhmYyUf2lGJBzbYAERzvkhfut3+O0SBn9FCni6n32yNGWdGzGaZEvQAkUSFcT2mv/IfMV2p5Nyao19JdWpDNVmFenYLM0GAgck68kYWPRc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707664114; c=relaxed/simple; bh=IvTIcU18qlQtiOl7Wv/JqJLqq3hP94HFMtbZnDwMaw8=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=N8Mok1nYCacgfM5QQoU3i9+bi+o39ZzMhTk3veK0NrTiYGSgTpP+jKbtHLdVuhOeJxqC2EVGl7SQvI1uXx95mZEoCggJqH1+K5ZF2q65QNizf5uFm+Os8aWO5LW+GdhzRsuVdhLBsV0DuV8//FrGKqDCU11KsSlPJx2rtGCzrA0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=aladdin.ru; spf=pass smtp.mailfrom=aladdin.ru; arc=none smtp.client-ip=91.199.251.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=aladdin.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=aladdin.ru From: Daniil Dulov <d.dulov@aladdin.ru> To: Russell King <linux@armlinux.org.uk> CC: Daniil Dulov <d.dulov@aladdin.ru>, Andrew Lunn <andrew@lunn.ch>, Heiner Kallweit <hkallweit1@gmail.com>, "David S. Miller" <davem@davemloft.net>, Jakub Kicinski <kuba@kernel.org>, <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <lvc-project@linuxtesting.org> Subject: [PATCH] net: sfp: remove redundant NULL check Date: Sun, 11 Feb 2024 07:08:24 -0800 Message-ID: <20240211150824.3947-1-d.dulov@aladdin.ru> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: EXCH-2016-02.aladdin.ru (192.168.1.102) To EXCH-2016-01.aladdin.ru (192.168.1.101) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790615750687136537 X-GMAIL-MSGID: 1790615750687136537 |
Series |
net: sfp: remove redundant NULL check
|
|
Commit Message
Daniil Dulov
Feb. 11, 2024, 3:08 p.m. UTC
bus->upstream_ops in sfp_register_bus() cannot be NULL. So remove
redundant NULL check.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Fixes: ce0aa27ff3f6 ("sfp: add sfp-bus to bridge between network devices and sfp cages")
Signed-off-by: Daniil Dulov <d.dulov@aladdin.ru>
---
drivers/net/phy/sfp-bus.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
Comments
On Sun, 2024-02-11 at 07:08 -0800, Daniil Dulov wrote: > bus->upstream_ops in sfp_register_bus() cannot be NULL. So remove > redundant NULL check. I'm unsure about that?!? in theory drivers could call sfp_bus_add_upstream()/phy_sfp_probe() with NULL ops, even it that very likely doesn't make any sense. @Russel, @Andrew: WDYT? Thanks, Paolo
On Tue, 13 Feb 2024 13:43:57 +0100 Paolo Abeni wrote: > On Sun, 2024-02-11 at 07:08 -0800, Daniil Dulov wrote: > > bus->upstream_ops in sfp_register_bus() cannot be NULL. So remove > > redundant NULL check. > > I'm unsure about that?!? in theory drivers could call > sfp_bus_add_upstream()/phy_sfp_probe() with NULL ops, even it that very > likely doesn't make any sense. > > @Russel, @Andrew: WDYT? Since Russell is AFK let me discard this instead of queuing. We'll resurrect if any of the maintainers sends review tags or alike.
On Sun, Feb 11, 2024 at 07:08:24AM -0800, Daniil Dulov wrote: > bus->upstream_ops in sfp_register_bus() cannot be NULL. So remove > redundant NULL check. > > Found by Linux Verification Center (linuxtesting.org) with SVACE. It probably would've been better to include in here details of the two paths that lead to this point, and indicate why it's safe to remove the NULL check. The first path is via sfp_register_socket(), which checks that bus->upstream_ops is not NULL prior to calling sfp_register_bus(). Therefore, "ops" can not be NULL when sfp_register_bus() is called via this path. The second path is via sfp_bus_add_upstream(), and this path assumes that the "ops" passed into this function will not be NULL. Nothing in this code makes that guarantee, and it's up to the design(er) to determine whether NULL is permitted or not. It's not something that an automated checker ought to be suggesting. In this particular instance, I, as the interface designer, do indeed intend that "ops" will not be NULL here, so the patch can remove the check is acceptable in this instance. However, I'll go back to my original point: this is *not* something that automated tools should be identifying, and it is *not* something that should be used to throw patches randomly out, especially where the commit message doesn't include human analysis details. > > Fixes: ce0aa27ff3f6 ("sfp: add sfp-bus to bridge between network devices and sfp cages") > Signed-off-by: Daniil Dulov <d.dulov@aladdin.ru> > --- > drivers/net/phy/sfp-bus.c | 14 ++++++-------- > 1 file changed, 6 insertions(+), 8 deletions(-) > > diff --git a/drivers/net/phy/sfp-bus.c b/drivers/net/phy/sfp-bus.c > index 850915a37f4c..829cb1dccc27 100644 > --- a/drivers/net/phy/sfp-bus.c > +++ b/drivers/net/phy/sfp-bus.c > @@ -478,14 +478,12 @@ static int sfp_register_bus(struct sfp_bus *bus) > const struct sfp_upstream_ops *ops = bus->upstream_ops; > int ret; > > - if (ops) { > - if (ops->link_down) > - ops->link_down(bus->upstream); > - if (ops->connect_phy && bus->phydev) { > - ret = ops->connect_phy(bus->upstream, bus->phydev); > - if (ret) > - return ret; > - } > + if (ops->link_down) > + ops->link_down(bus->upstream); > + if (ops->connect_phy && bus->phydev) { > + ret = ops->connect_phy(bus->upstream, bus->phydev); > + if (ret) > + return ret; > } > bus->registered = true; > bus->socket_ops->attach(bus->sfp); > -- > 2.25.1 > >
> However, I'll go back to my original point: this is *not* something > that automated tools should be identifying, and it is *not* something > that should be used to throw patches randomly out, especially where > the commit message doesn't include human analysis details. Hi Daniil Could you work on SVACE and make it dump how it decided it was safe to remove the NULL check. I assume it found the path via sfp_register_socket(), and the NULL check in that. So it should be able to dump that info in some form. sfp_bus_add_upstream() seems more interesting and it would be interesting to know why it though a NULL from there was impossible. It would be great if the tool dumped some text which could be cut/paste into the commit message as a justification for the change. Andrew
diff --git a/drivers/net/phy/sfp-bus.c b/drivers/net/phy/sfp-bus.c index 850915a37f4c..829cb1dccc27 100644 --- a/drivers/net/phy/sfp-bus.c +++ b/drivers/net/phy/sfp-bus.c @@ -478,14 +478,12 @@ static int sfp_register_bus(struct sfp_bus *bus) const struct sfp_upstream_ops *ops = bus->upstream_ops; int ret; - if (ops) { - if (ops->link_down) - ops->link_down(bus->upstream); - if (ops->connect_phy && bus->phydev) { - ret = ops->connect_phy(bus->upstream, bus->phydev); - if (ret) - return ret; - } + if (ops->link_down) + ops->link_down(bus->upstream); + if (ops->connect_phy && bus->phydev) { + ret = ops->connect_phy(bus->upstream, bus->phydev); + if (ret) + return ret; } bus->registered = true; bus->socket_ops->attach(bus->sfp);