Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3647973pxb; Wed, 13 Oct 2021 10:03:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDO2xu8pRalcLV5mxV7JYnGO7+Hqb4Ge1rtPLNuWdFld5XMvgb9FJOkmkQ9opFVgEJVc8w X-Received: by 2002:a17:907:7691:: with SMTP id jv17mr463319ejc.378.1634144608894; Wed, 13 Oct 2021 10:03:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634144608; cv=none; d=google.com; s=arc-20160816; b=CVwgZbF0hbHpSC/yeOiZIxjFo3Jv2I+NaFe8MW66bzGFcU3RW1btKa8AetSPPvOUjm tz4esEgptButnRIrGhvC0ZWARIxWxVL3uC9/u8xtIXpsFv9L7VaASaRAQlRy3s07gqtD gSD0iLLeZM8pQd/np7pTubTlzVl5MWa6N1IkTBG3U1XvOuAiGRfbhiUsr1ZD5Bv8Un/k 7XkbbU1ZyMWX6KcyxjopQJ5y7q1Pd2C34m0qJ37RA/E0kPxD6YA+QtStzqT08gTGtAbW f/wbLfWcSmWM9usVDxESloHvGLR4CPr8rUWOhEDfqamwMDcAufwpWVV1eNADDViYY2ut j3hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=WizGXyqlxBR0wiMfIIEQnydyfDGuD0BLtBHnvPMHVPM=; b=pzQ5OCDTgrSGRgkPFL7oVl7LAPEeTsE2CrJGCL1f00Y65anctZrCBDu2GSAQNSe/rS +t+s31cDt8eUCNMntATLoo37tIIX8RRoJjcWNusF6iUhs0smi7QkS+a5hJErZGISQZbS DaArAE0rVcTbxDVuUNrlFck1YW7PfJuzKbuwxl7YYV3fjW4ybsh6DRuyFvlwHpqBStNE M/Agm1B4Zs22WgDyZh2m9cqr6VQzGx9XubpdZIFH8ZqM2yz82tEQRb1tP9WPTDJdwfaz 5y1H2rOBHDVmv7IHODmi4uw+IDI/trJ7t8zYM32R7+ZBAh3cKq7W+9NByhxSjKodDaye 5dAQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cc12si51924edb.194.2021.10.13.10.03.03; Wed, 13 Oct 2021 10:03:28 -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; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237682AbhJMRAh (ORCPT + 99 others); Wed, 13 Oct 2021 13:00:37 -0400 Received: from mga12.intel.com ([192.55.52.136]:20038 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230415AbhJMRAf (ORCPT ); Wed, 13 Oct 2021 13:00:35 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10136"; a="207594565" X-IronPort-AV: E=Sophos;i="5.85,371,1624345200"; d="scan'208";a="207594565" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2021 09:58:31 -0700 X-IronPort-AV: E=Sophos;i="5.85,371,1624345200"; d="scan'208";a="547986866" Received: from smile.fi.intel.com (HELO smile) ([10.237.72.159]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2021 09:58:23 -0700 Received: from andy by smile with local (Exim 4.95) (envelope-from ) id 1makM2-0001gg-8h; Wed, 13 Oct 2021 22:55:58 +0300 Date: Wed, 13 Oct 2021 22:55:58 +0300 From: Andy Shevchenko To: Emil Renner Berthing Cc: linux-riscv , devicetree , linux-clk , "open list:GPIO SUBSYSTEM" , "open list:SERIAL DRIVERS" , Palmer Dabbelt , Paul Walmsley , Rob Herring , Michael Turquette , Stephen Boyd , Thomas Gleixner , Marc Zyngier , Philipp Zabel , Linus Walleij , Greg Kroah-Hartman , Daniel Lezcano , Jiri Slaby , Maximilian Luz , Sagar Kadam , Drew Fustini , Geert Uytterhoeven , Anup Patel , Atish Patra , Matteo Croce , Linux Kernel Mailing List , Huan Feng Subject: Re: [PATCH v1 12/16] pinctrl: starfive: Add pinctrl driver for StarFive SoCs Message-ID: References: <20211012134027.684712-1-kernel@esmil.dk> <20211012134027.684712-13-kernel@esmil.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 13, 2021 at 06:38:14PM +0200, Emil Renner Berthing wrote: > On Tue, 12 Oct 2021 at 19:03, Andy Shevchenko wrote: > > On Tue, Oct 12, 2021 at 4:43 PM Emil Renner Berthing wrote: ... > > > +free_pinmux: > > > + devm_kfree(dev, pinmux); > > > +free_pins: > > > + devm_kfree(dev, pins); > > > +free_grpname: > > > + devm_kfree(dev, grpname); > > > > What the heck?! > > Just to be clear. You mean we don't need to explicitly free them > because they're tied to the device right? I don't think the device > will go away just because a single device tree entry can't be parsed, > so on such errors this garbage would be left behind. You can still > argue we shouldn't optimize for broken device trees, I just want to > make it at conscious decision. If you are using devm_kfree() it is quite likely shows either of the following issues: * you mustn't use devm_*() in the first place due to object lifetime; * you shouldn't use devm_kfree() since this is the whole point of devm. > > > +free_pgnames: > > > + devm_kfree(dev, pgnames); > > > > Ditto. ... > > > +out: > > > > Useless label. > > Hmm.. my compiler disagrees. The comment implies that you return directly instead of using `goto out;`. > > > + return ret; ... > > > + v = pinmux[i]; > > > + dout = ((v & BIT(7)) << (31 - 7)) | ((v >> 24) & 0xffU); > > > + doen = ((v & BIT(6)) << (31 - 6)) | ((v >> 16) & 0xffU); > > > + din = (v >> 8) & 0xffU; > > > > What is this voodoo for? > > In order to do pinmux we need the following pieces of information from > the device tree for each pin ("GPIO" they call it): > > output signal: 0-133 + 1bit reverse flag > output enable signal: 0-133 + 1bit reverse flag > optional input signal: 0-74 + special "none" value, right now 0xff > gpio number: 0-63 > > As the code is now all that info is packed into a u32 for each pin > using the GPIOMUX macro defined in the dt-binding header added in > patch 10. There is also a diagram for how this packing is done. The > above voodoo is for unpacking that. > > I'd very much like to hear if you have a better solution for how to > convey that information from the device tree to here. At very least this code should have something like above in the comment. ... > > > + if (din != 0xff) > > > + reg_din = sfp->base + GPIO_IN_OFFSET + 4 * din; > > > + else > > > + reg_din = NULL; > > > > This looks like you maybe use gpio-regmap instead? > > This was discussed at length when Drew sent in the GPIO part of this code: > https://lore.kernel.org/linux-riscv/20210701002037.912625-1-drew@beagleboard.org/ > The conclusion was that because pinmux and controlling the pins from > software in GPIO mode uses the same registers it is better to do a > combined driver like this that can share the lock among other things. And what does prevent exactly to base the GPIO part on gpio-regmap? ... > > > +static const unsigned char starfive_drive_strength[] = { > > > + 14, 21, 28, 35, 42, 49, 56, 63, > > > > Why table? Can you simply use the formula?! > > Heh, yeah. So these are rounded values from a table and I never > noticed that after rounding they follow a nice arithmetic progression. > It'll probably still be nice to have an explanation in the comments > about the formula then. Yup! > > > +}; ... > > > + irq_set_handler_locked(d, handle_bad_irq); > > > > Why is this here? Move it to ->probe(). > > My thinking was that if something tries to set a an unsupported irq > type, we should make sure the caller doesn't get spurious interrupts > because we left the handler at its old value. You already assigned to this handler in the ->probe(), what's this then? ... > > > + if (value <= 6) > > > + writel(value, sfp->padctl + IO_PADSHARE_SEL); > > > + else > > > > > + dev_err(dev, "invalid signal group %u\n", value); > > > > Why _err if you not bail out here? > > My thinking was that if the device tree specifies an invalid signal > group we should just leave the setting alone and not break booting, > but still be loud about it. Maybe that's too lenient and it's better > to crash and burn immediately if someone does that. Here is inconsistency between level of the message and following action. There are (rare!) cases when it's justified, but I believe it's not the case here. You have two choices or justify why you have to use error level without stopping process. ... All uncommented stuff you agreed on, correct? -- With Best Regards, Andy Shevchenko