Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3959169rdh; Tue, 28 Nov 2023 08:09:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IFV1d4PF7x17tobED9G5CtJL10Z1yGGgkDI9a1cI75orLSqKYexIGKw/wxXPaP+tGCPy9Ki X-Received: by 2002:a17:903:1c5:b0:1cf:a91a:556 with SMTP id e5-20020a17090301c500b001cfa91a0556mr15815821plh.8.1701187760946; Tue, 28 Nov 2023 08:09:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701187760; cv=none; d=google.com; s=arc-20160816; b=bc2xOUvvgsl6IyNzEvQvzKt2XhTqVDszcQZoj1SOj331ukuTf8cDgYne1i5oR25Meh 0kKZTGsPxFg0m3gkE85Tqabw3H3C7WMyyP034EFgk6eSuFy7IIh/i4HsK7iqCFVTLbt0 i+wnBVveeD+IHUrgHPwhyW7vslIAB6hAD1MQSEKSiYUKeQhuss03/5x7lxNIEnhHWiCf eaM4kKn3Vd8lMCi4ARqovYFpbNmHZcZ97GZ27cFAjfY+sZGWr9KYtPVWtIGteU5cC7xY qwN+VxdrjKIwLOky2ity4sANGCkhvf8eRAa5DqU2VUVHnQ4DglBujl1WjPog7bYV3TG5 Lxnw== 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 :dkim-signature; bh=jAA8DgGXWK2s9xUJe4aVcnexS8t/cNZnAnhPpaizU7U=; fh=TFQI+YzLUQlYl4kOcmLiE6H8IBxzIqYzJVz8pYCx9C4=; b=Vn3X7jwTUOf9NFp+27ptR06WO3z6NHl3NrLLqIU2S5c1muP84C70Hvon1SX3apT9K3 z85UlRbsDGYz7RelcQKhupj3+5v5ljWHkZV9joG8F4JWIeEEER03ApFHJ1wtpjtrep/p Bes4SuK7QjkL1Ry5MI/z8+aK40Xb2qXyWrsHkAprwwGHzgogijTaUA3t0VjmwYdqTRu4 uOaUPz/0uLRwGTgJ9XnZK/J/NLUnka/7QsmbTBV9/6bcV+hMHN3+OkLDFtSfolwOU1W+ HyjVEtA6pWmtk1tVivkgaUYyWNqxQRnX13DbsJMTb2ve9e0vXVTo8kkrmi2zktPk1YmP ygEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="n/GbhaiQ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id m2-20020a170902db0200b001ce5b8081a5si5601772plx.382.2023.11.28.08.09.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 08:09:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="n/GbhaiQ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 222318045945; Tue, 28 Nov 2023 08:09:08 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344123AbjK1QI6 (ORCPT + 99 others); Tue, 28 Nov 2023 11:08:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232712AbjK1QI4 (ORCPT ); Tue, 28 Nov 2023 11:08:56 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B48C1BC; Tue, 28 Nov 2023 08:09:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701187743; x=1732723743; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=bUDTt3o1DE03wIRYkYueaBcLdCqYQmU2dGzx0wmGR44=; b=n/GbhaiQbdnyPWod7LuIbCwAATzIdEUefqGmTkarLRJwivHZTa9W6eb4 xmZt4Y3qlUAhlx/PBIww5pZmHy1BoXA+hUUAm284WVYUQqTW4cbepGMma x34gm27LBfHhqkW4RoncSpL7z46udZftAGtdRGdLpYGxUrs6g7PzbEf1S F+Tp8A/fR0zMGXiJPfe0yOaoKusmj0plFu2C9oqLoraxcoGVQi4VNSZDV fN4uunE+svXDuEHwB/QIcIGnvbUuzGrfX5g9eNOM2x/t94sVvHECAv19m fMBEDnIsENS90UQ9DcDgAZLZEvMO3zunXLLjrQlK8kov8f/kKKwr9Qf14 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10908"; a="373123836" X-IronPort-AV: E=Sophos;i="6.04,234,1695711600"; d="scan'208";a="373123836" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Nov 2023 08:09:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10908"; a="1100152703" X-IronPort-AV: E=Sophos;i="6.04,234,1695711600"; d="scan'208";a="1100152703" Received: from smile.fi.intel.com ([10.237.72.54]) by fmsmga005.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Nov 2023 08:09:01 -0800 Received: from andy by smile.fi.intel.com with local (Exim 4.97) (envelope-from ) id 1r80du-00000000ClQ-2Zof; Tue, 28 Nov 2023 18:08:58 +0200 Date: Tue, 28 Nov 2023 18:08:58 +0200 From: Andy Shevchenko To: Bartosz Golaszewski Cc: Linus Walleij , Kent Gibson , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: Re: [PATCH 2/2] gpio: use a mutex to protect the list of GPIO devices Message-ID: References: <20231127193716.63143-1-brgl@bgdev.pl> <20231127193716.63143-2-brgl@bgdev.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231127193716.63143-2-brgl@bgdev.pl> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 28 Nov 2023 08:09:08 -0800 (PST) On Mon, Nov 27, 2023 at 08:37:16PM +0100, Bartosz Golaszewski wrote: > From: Bartosz Golaszewski > > The global list of GPIO devices is never modified or accessed from > atomic context so it's fine to protect it using a mutex. Add a new > global lock dedicated to the gpio_devices list and use it whenever > accessing or modifying it. > > While at it: fold the sysfs registering of existing devices into > gpiolib.c and make gpio_devices static within its compilation unit. ... > + scoped_guard(mutex, &gpio_devices_lock) { This is a lot of churn with this because of switching to RAII. Can the body be firstly moved to a helper? > + /* > + * TODO: this allocates a Linux GPIO number base in the global > + * GPIO numberspace for this chip. In the long run we want to > + * get *rid* of this numberspace and use only descriptors, but > + * it may be a pipe dream. It will not happen before we get rid > + * of the sysfs interface anyways. > + */ ... > list_for_each_entry(gdev, &gpio_devices, list) > + if (index-- == 0) > return gdev; I believe this is better with outer {}. -- With Best Regards, Andy Shevchenko