Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4680333imu; Sun, 25 Nov 2018 08:09:52 -0800 (PST) X-Google-Smtp-Source: AJdET5dQ3CclxBRwxpjNBtLETR7kqVpu864qNAv7E+PqmXgA2MH+FxzsNBbwZKNPOFR9PkjF+XUL X-Received: by 2002:aa7:804e:: with SMTP id y14-v6mr23643916pfm.73.1543162192330; Sun, 25 Nov 2018 08:09:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543162192; cv=none; d=google.com; s=arc-20160816; b=PLmw0e0R0Wm0ERgQwolfN8O1gsz+MVKnxjEt+OsvDhUXkAytupCGWzMLyOTSvW04jx wmq8gC6hnwDeAoDuDK5S/K8iZGXtMrWh/1ghH3Yc+tpaiA5BahnPOQ28qH6pmEyi6qDa 5p3L3pUOI6dGSxvgVVLsSEUH8f5VYMw/zi2hZB3rc8UGZEnv3FEL7M1yjd8qs3aKvRe4 c3FjcHxUUNiO4L8NoloY0bIZS22EELyo2EAzDDDbxZgEdUfBDkyJO03oPbIGrKZH+jvy 8GMhffiNfY5VYESaVP1zpVHJkeqvl0iEXWtrrGuazdDsLGKkafykPS0KUrurWNoc7j7m Wt/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=VxjOHn27Usr/08UrqWVjQGIyziwUPnQd3aIB1lD1lBM=; b=RHoxtdSKEXLuVWouGJEHmZCiWrBU92D+idv22Y03Ryua8A3B4VLiqrAbVotw35sDSG jsWkNh4o17asHaN0sK2TGeaXjoia9Q8EP//24hJ7zPZrD6cU/g8rks0CpYD5Hrwj73Qf +2Pip2ZmrFNzOv6UQBau1l+cJF900Avhd5AtKF3GOAfeeAhNagJjtIOgr+v/LPKWW4Hz fSLlqj+DG7wS51jTYork5r/PUr1ydgy/pRDXcWDQzNZI0XoHCl+hWamZQQW3NRtGyy4d W14GwKDAhc4aFrXUfNFtrxMpJnIFDRQ49U5/KdPeTurjvFuA2rMILjPGvqQYuv0ThwrW 5Qzw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j2si25103715plt.93.2018.11.25.08.09.34; Sun, 25 Nov 2018 08:09:52 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726562AbeKZDAT (ORCPT + 99 others); Sun, 25 Nov 2018 22:00:19 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:51402 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726226AbeKZDAT (ORCPT ); Sun, 25 Nov 2018 22:00:19 -0500 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1gQwxo-0007lj-AW; Sun, 25 Nov 2018 16:08:52 +0000 From: Colin King To: Roopa Prabhu , Nikolay Aleksandrov , "David S . Miller" , bridge@lists.linux-foundation.org, netdev@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][V2] net: bridge: remove redundant checks for null p->dev and p->br Date: Sun, 25 Nov 2018 16:08:51 +0000 Message-Id: <20181125160851.6919-1-colin.king@canonical.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King A recent change added a null check on p->dev after p->dev was being dereferenced by the ns_capable check on p->dev. It turns out that neither the p->dev and p->br null checks are necessary, and can be removed, which cleans up a static analyis warning. As Nikolay Aleksandrov noted, these checks can be removed because: "My reasoning of why it shouldn't be possible: - On port add new_nbp() sets both p->dev and p->br before creating kobj/sysfs - On port del (trickier) del_nbp() calls kobject_del() before call_rcu() to destroy the port which in turn calls sysfs_remove_dir() which uses kernfs_remove() which deactivates (shouldn't be able to open new files) and calls kernfs_drain() to drain current open/mmaped files in the respective dir before continuing, thus making it impossible to open a bridge port sysfs file with p->dev and p->br equal to NULL. So I think it's safe to remove those checks altogether. It'd be nice to get a second look over my reasoning as I might be missing something in sysfs/kernfs call path." Thanks to Nikolay Aleksandrov's suggestion to remove the check and David Miller for sanity checking this. Detected by CoverityScan, CID#751490 ("Dereference before null check") Fixes: a5f3ea54f3cc ("net: bridge: add support for raw sysfs port options") Signed-off-by: Colin Ian King --- V2: remove checks instead of moving them before the dereference of p->dev. --- net/bridge/br_sysfs_if.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/net/bridge/br_sysfs_if.c b/net/bridge/br_sysfs_if.c index 7c87a2fe5248..88715edb119a 100644 --- a/net/bridge/br_sysfs_if.c +++ b/net/bridge/br_sysfs_if.c @@ -320,9 +320,6 @@ static ssize_t brport_store(struct kobject *kobj, if (!rtnl_trylock()) return restart_syscall(); - if (!p->dev || !p->br) - goto out_unlock; - if (brport_attr->store_raw) { char *buf_copy; -- 2.19.1