From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B8DEC74A5B for ; Wed, 29 Mar 2023 19:35:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229667AbjC2Tff (ORCPT ); Wed, 29 Mar 2023 15:35:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229461AbjC2Tfc (ORCPT ); Wed, 29 Mar 2023 15:35:32 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B565C469C; Wed, 29 Mar 2023 12:35:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:From:Sender:Reply-To:Subject: Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=9Ip60VxQO8vIEjsVQuk6WZlBLCQN328zDAYmxQho2Uk=; b=oNr9cPXYVHQF9aWQrgtHuUbaL4 rrNePszDIqfOYFfGJC50qIve5P6TNCg56eDFOWxZFl5EU4a6rvy6hSSeNXqQEUrqJjaeXThOcY7sP yHibUzHcsx5RDU3sLn98Kg1qzVw5h5E6OXiPoAvByexD169ZM+yrl2MQni+L90RuZtF4=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1phbZl-008nTP-Sg; Wed, 29 Mar 2023 21:35:17 +0200 Date: Wed, 29 Mar 2023 21:35:17 +0200 From: Andrew Lunn To: Daniel Golle Cc: netdev@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Matthias Brugger , AngeloGioacchino Del Regno , Sean Wang , Landen Chao , DENG Qingfang , Philipp Zabel , Sam Shih , Lorenzo Bianconi , John Crispin , Felix Fietkau Subject: Re: [RFC PATCH net-next v3 03/15] net: dsa: mt7530: use regmap to access switch register space Message-ID: References: <754322262cd754aee5916954b8e651989b229a09.1680105013.git.daniel@makrotopia.org> <7eb07ed2-2b1c-44fa-b029-0ecad7872fd2@lunn.ch> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 29, 2023 at 07:33:17PM +0100, Daniel Golle wrote: > On Wed, Mar 29, 2023 at 06:24:21PM +0200, Andrew Lunn wrote: > > Thanks for splitting this patchset up. This is much easier to review. > > > > > +static u32 > > > +mt7530_mii_read(struct mt7530_priv *priv, u32 reg) > > > +{ > > > + int ret; > > > + u32 val; > > > + > > > + ret = regmap_read(priv->regmap, reg, &val); > > > + if (ret) { > > > + dev_err(priv->dev, > > > + "failed to read mt7530 register\n"); > > > + return ret; > > > > This is a u32 function. ret should be negative on error, which is > > going to be turned positive in order to return a u32. So you probably > > want to make this an int function. > > This is a pre-existing flaw in the code. As we are accessing 32-bit > registers there has just never been any meaningful error handling. O.K. At least i would not return the negative error code. Return 0, or 0xdeadbeef or something. And consider adding a WARN_ON_ONCE() so it is very loud when it goes wrong. > I guess the correct solution would be to not use the return value only > to indicate success or error, and use an additional u32* parameter for > the read value. Yes, that is what mv88e6xxx does. > However, I was hestitating to convert all the calls (they are many) to > follow that improved paradigm. Yes, leave that for another time. Andrew