Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2747878pxj; Mon, 31 May 2021 09:44:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwL8Q3nTNLDSiZ5tiWjZAw7p+HzAR3mQJL/vWj4i8wHg5nSB5khSo66Zscr72IFPg/SCNck X-Received: by 2002:a17:906:3ed0:: with SMTP id d16mr23333583ejj.16.1622479442015; Mon, 31 May 2021 09:44:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622479442; cv=none; d=google.com; s=arc-20160816; b=gyNhOEfdEutHB8W29cRHdpyDNB5NoTQ2tYUeKVyZWoHeSmGZ5HIp2VGH18HsiLK7X8 vldygEx2cAR7Qf0tfbCW42ox2Df+tuiWmeFxl3ZTtsNTAFZIYz71zRgGKyIPcFxEF+bK x7vsPXUlUUeBMFjhDk82C4Y01L6JSVUMGufvhKmv9aHo7hgPiRJ0I0OL5aQPcxT6dguJ ayb9i1QIX1qrW5G7vNp25+BAy3bfmGaMAD+VdEGaGWI8ZwC1BGN+mht6w/gfU8JwAR9n pHLiLW83LgpUYIeOmn5xkMogt+spf/9YMuNFz6xnk+iefEWEyQDILOhGCFHq0/j25cU6 Fw5g== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BqM6m88dr7hmRXQ2AD40YNjbCeQ4BtYoPtfMdCGxbZk=; b=MvOnMusWWAt2Nz8/Bs3pmZINc5arx4JNTKzS4P/s+QpjV4B75LS8tqK3obGhsvQIO3 gg3cFLDASUtmwr5qyqGd5OyII61u8jHETaSW/pf+/eJpcIpr6LzV2dtZtkEuXSE73bMb 0iHqaaXU9jtIv7fL2dZr9hDi2w9syCGFZD8GR8aXdWzIOk0p2VqSNzBK7SwsUIGtPXaQ QRcaayQiMOdbqJ4iG73bGOVtkkDBVkgsuxWHeDML+bCFsYKqaRBrqVdy+URv0MvwI74d 5/Uca7HDt8vrXSVWAvXKXRmPYXb5pEzk834QhxeNTQZ9ZdgCnJXds8OPXuxoRc0dSNyO 0/6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=T7qiOAxy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w11si6221793ejq.499.2021.05.31.09.43.39; Mon, 31 May 2021 09:44:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=T7qiOAxy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233891AbhEaQmJ (ORCPT + 99 others); Mon, 31 May 2021 12:42:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:48436 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231377AbhEaOvo (ORCPT ); Mon, 31 May 2021 10:51:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1617F61931; Mon, 31 May 2021 13:58:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622469500; bh=5kDhT8Zhm3TbjgG4JxDKroPuOS9jtDhk39zWh2ldOZs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T7qiOAxyALyCLo/gd1zByE4Fab15quzraMG8mO6WAta8FACGGtwjfy49Gf3tS4QcY k1/d0OyBOxAkiLZYR7z8AbMrpOs8Q3U8AYj1FXEki/Krx6HUgJSgDfOBHcAa1zimxd Sbog58WUB9y8rSdjdG+D4JytNnAR6M0klpeKbKuU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vladimir Oltean , Florian Fainelli , Andrew Lunn , "David S. Miller" , Sasha Levin Subject: [PATCH 5.12 222/296] net: dsa: fix error code getting shifted with 4 in dsa_slave_get_sset_count Date: Mon, 31 May 2021 15:14:37 +0200 Message-Id: <20210531130711.293363340@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130703.762129381@linuxfoundation.org> References: <20210531130703.762129381@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vladimir Oltean [ Upstream commit b94cbc909f1d80378a1f541968309e5c1178c98b ] DSA implements a bunch of 'standardized' ethtool statistics counters, namely tx_packets, tx_bytes, rx_packets, rx_bytes. So whatever the hardware driver returns in .get_sset_count(), we need to add 4 to that. That is ok, except that .get_sset_count() can return a negative error code, for example: b53_get_sset_count -> phy_ethtool_get_sset_count -> return -EIO -EIO is -5, and with 4 added to it, it becomes -1, aka -EPERM. One can imagine that certain error codes may even become positive, although based on code inspection I did not see instances of that. Check the error code first, if it is negative return it as-is. Based on a similar patch for dsa_master_get_strings from Dan Carpenter: https://patchwork.kernel.org/project/netdevbpf/patch/YJaSe3RPgn7gKxZv@mwanda/ Fixes: 91da11f870f0 ("net: Distributed Switch Architecture protocol support") Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli Reviewed-by: Andrew Lunn Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/dsa/slave.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/net/dsa/slave.c b/net/dsa/slave.c index 992fcab4b552..8dd7c8e84a65 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -787,13 +787,15 @@ static int dsa_slave_get_sset_count(struct net_device *dev, int sset) struct dsa_switch *ds = dp->ds; if (sset == ETH_SS_STATS) { - int count; + int count = 0; - count = 4; - if (ds->ops->get_sset_count) - count += ds->ops->get_sset_count(ds, dp->index, sset); + if (ds->ops->get_sset_count) { + count = ds->ops->get_sset_count(ds, dp->index, sset); + if (count < 0) + return count; + } - return count; + return count + 4; } return -EOPNOTSUPP; -- 2.30.2