From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751707AbdAaSKK convert rfc822-to-8bit (ORCPT ); Tue, 31 Jan 2017 13:10:10 -0500 Received: from shards.monkeyblade.net ([184.105.139.130]:39802 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751426AbdAaSJq (ORCPT ); Tue, 31 Jan 2017 13:09:46 -0500 Date: Tue, 31 Jan 2017 13:09:44 -0500 (EST) Message-Id: <20170131.130944.1449047914150613032.davem@davemloft.net> To: vincent.stehle@laposte.net Cc: linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, sgoutham@cavium.com Subject: Re: [PATCH] net: thunderx: avoid dereferencing xcv when NULL From: David Miller In-Reply-To: <20170130140643.24182-1-vincent.stehle@laposte.net> References: <20170130140643.24182-1-vincent.stehle@laposte.net> X-Mailer: Mew version 6.7 on Emacs 24.5 / Mule 6.0 (HANACHIRUSATO) Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-8859-1 Content-Transfer-Encoding: 8BIT X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.12 (shards.monkeyblade.net [149.20.54.216]); Tue, 31 Jan 2017 09:10:43 -0800 (PST) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vincent Stehlé Date: Mon, 30 Jan 2017 15:06:43 +0100 > This fixes the following smatch and coccinelle warnings: > > drivers/net/ethernet/cavium/thunder/thunder_xcv.c:119 xcv_setup_link() error: we previously assumed 'xcv' could be null (see line 118) [smatch] > drivers/net/ethernet/cavium/thunder/thunder_xcv.c:119:16-20: ERROR: xcv is NULL but dereferenced. [coccinelle] > > Fixes: 6465859aba1e66a5 ("net: thunderx: Add RGMII interface type support") > Signed-off-by: Vincent Stehlé > Cc: Sunil Goutham I've applied this, but wow this is some code that needs fixing on a more fundamental level. Having a global pointer for a device private and assuming only one instance of a PCI device ID will ever be probe in a system is really wrong. This is true even in all known machines or configurations this might be true. It leads to exactly the kinds of problems shown here. Objects should be probed by instance, and if operations need to be performed on it, a pointer to the software state for that object instance should be passed around. Rather than having an implicit single object.