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 2E5ABEB64DD for ; Thu, 17 Aug 2023 12:39:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350889AbjHQMjL (ORCPT ); Thu, 17 Aug 2023 08:39:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231683AbjHQMi4 (ORCPT ); Thu, 17 Aug 2023 08:38:56 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C78182D57; Thu, 17 Aug 2023 05:38:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692275934; x=1723811934; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=XKAlDtu8w5r2ImV3XxMTRJjxDaYlAichBPMvi13fXvc=; b=VqsbESa+YHRjI9coof1u0zvfGUtLwbjTcar+YWRnAKkSD2c0kYWxjOiC b8XU7V8aQhE1lSF1Oe5ae8JVwHZKMlhgtJ9lTdKNRwcIOPhMYzEo3JBPP YjE0EzJ73tghqOnxlwzqnp8h8j94477VV+Hch5d3q9AauauQn6dRs3BBt /7pV5zgUWZU016inb6dtw6jhGsvLzcqHs/yQXq5VAlgAvMaogjIoALsgD 3j7Kl17drHXKFELgi0qsHJLixqLNdWHWbMUS6XNXDqUbZBETTgkt5nurq R1PaL7kzqnrpJoype5MoMDTPujLDaUkAjjOh/8GFiBBPVmlH8fVldJ+Km w==; X-IronPort-AV: E=McAfee;i="6600,9927,10803"; a="403779073" X-IronPort-AV: E=Sophos;i="6.01,180,1684825200"; d="scan'208";a="403779073" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Aug 2023 05:38:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10803"; a="981142718" X-IronPort-AV: E=Sophos;i="6.01,180,1684825200"; d="scan'208";a="981142718" Received: from smile.fi.intel.com ([10.237.72.54]) by fmsmga006.fm.intel.com with ESMTP; 17 Aug 2023 05:38:52 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1qWcH4-00BiQC-0y; Thu, 17 Aug 2023 15:38:50 +0300 Date: Thu, 17 Aug 2023 15:38:50 +0300 From: Andy Shevchenko To: Bartosz Golaszewski Cc: Linus Walleij , Kent Gibson , Jonathan Corbet , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Bartosz Golaszewski Subject: Re: [PATCH v5] gpio: consumer: new virtual driver Message-ID: References: <20230815185650.152968-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-doc@vger.kernel.org On Thu, Aug 17, 2023 at 02:14:04PM +0200, Bartosz Golaszewski wrote: > On Thu, Aug 17, 2023 at 12:03 PM Andy Shevchenko > wrote: > > On Tue, Aug 15, 2023 at 08:56:50PM +0200, Bartosz Golaszewski wrote: ... > > > + struct gpio_consumer_device *dev = lookup->parent; > > > + > > > + guard(mutex)(&dev->lock); > > > + > > > + return sprintf(page, "%s\n", lookup->key); (1) ... > > > +static ssize_t > > > +gpio_consumer_lookup_config_offset_show(struct config_item *item, char *page) > > > +{ > > > + struct gpio_consumer_lookup *lookup = to_gpio_consumer_lookup(item); > > > + struct gpio_consumer_device *dev = lookup->parent; > > > + unsigned int offset; > > > + > > > + scoped_guard(mutex, &dev->lock) > > > + offset = lookup->offset; > > > + > > > + return sprintf(page, "%d\n", offset); > > > > Consistently it can be simplified same way > > > > guard(mutex)(&dev->lock); > > > > return sprintf(page, "%d\n", lookup->offset); > > > > BUT. Thinking about this more. With guard() we put sprintf() inside the lock, > > which is suboptimal from runtime point of view. So, I think now that all these > > should actually use scoped_guard() rather than guard(). > > > > Precisely why I used a scoped guard here. Same elsewhere. So the 1) has to be amended then. > > > +} ... > > > + enum gpio_lookup_flags flags; > > > + > > > + flags = gpio_consumer_lookup_get_flags(item); > > > > This is perfectly one line < 80 characters. > > There's nothing wrong with setting the variable on another line though. Why do we need 3 LoCs instead of a single one? Do you increase your line statistics? :-) I really would like to know the rationale behind this. -- With Best Regards, Andy Shevchenko