Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3981730rdh; Tue, 28 Nov 2023 08:41:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IGyxkrEyYBIXHQ/fY7Qy7OlleroxP3grR6VJkTXPQ/QOMnoSurEPelF/K3o2+E1fHb8zHI4 X-Received: by 2002:a17:90b:3a8b:b0:285:cc9c:75a6 with SMTP id om11-20020a17090b3a8b00b00285cc9c75a6mr8631625pjb.32.1701189704082; Tue, 28 Nov 2023 08:41:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701189704; cv=none; d=google.com; s=arc-20160816; b=LeSfTYCClk1o2rzrtUPvMTnelc+qoQIZ4C6c+vCztF80anvEtMeZb46w5h2DpzpTRe bRXmTD1AjY31XoRFUaNL92ti0k0lKsY6GyyGJKRl2aab/OQlYj5BR5G2rqwa/82k6+na 7ngOXYJ+XZoiWM+w+4nLjHkxEMIaJ/fc2XQ30ZDRHVsjKQxZ7LVbIJWzDIV2pCTJnb7X pmoi/GA6IISrzGCLUupsAWb7HKTrWEUjEPObHgw/OqHkxrsDRGoVdRbk2d1luHSk6m1R nHicGb+dxEUlocryyBLmI8mQySk9Tmlc9WT0ZTP1K105bMdPyq9hPUOquH2gw472PXjS B2Bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=XmTesqK+F/QJOwGcug6iguQ/D1cpFRALPok0GTAiegc=; fh=NA2IZTsBFwjREUcds8Nt2e3faPWWUm3ShfnoxYpp9Xc=; b=QMsVH7PRAqI5ZeQQw94DOwcnQ+Ldy+QqnYUc1VxIATW1ph6spFRjVYSwx2JCa5rba8 67vT2yRgbnW5k7lGxWe3q1gzCOOtoDEUuLsZx+oaj5cUSvb/ArShuvx3BzVA6ANBJH3M BnM4yA7WiUjLnX7Enxdt62iGwS1udVYgU7vaj7xJuDmMVgG1MIPty+n+rfiHloOMmMaI FcKyMTtRU1GV3nRvZW9+rcLi2eUEQWEus/dfbkDe9clAbUrIpLAVvPWGUaE31E/4/wIi Tmbdo4pNkjclWeLWVbimRvPpcc5wO9hx96l/HfdhGZ2gga8Xqk5tHFgVMLlOHI8xRBxI XtVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=W6iio8H0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id pd9-20020a17090b1dc900b002859ad34f7bsi9953410pjb.92.2023.11.28.08.41.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 08:41:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=W6iio8H0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id E924F807C868; Tue, 28 Nov 2023 08:40:36 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344544AbjK1QkV (ORCPT + 99 others); Tue, 28 Nov 2023 11:40:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229532AbjK1QkT (ORCPT ); Tue, 28 Nov 2023 11:40:19 -0500 Received: from mail-oo1-xc35.google.com (mail-oo1-xc35.google.com [IPv6:2607:f8b0:4864:20::c35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2A11D6 for ; Tue, 28 Nov 2023 08:40:25 -0800 (PST) Received: by mail-oo1-xc35.google.com with SMTP id 006d021491bc7-58a42c3cbb8so3316124eaf.3 for ; Tue, 28 Nov 2023 08:40:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1701189625; x=1701794425; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=XmTesqK+F/QJOwGcug6iguQ/D1cpFRALPok0GTAiegc=; b=W6iio8H0DjYnScIKoSjJxxKpR6lzuR0bWtjfKpNAnwaySc27ItVi06kcA/sYM2/O4e qvnL/aK19jjR2v4dMfCzAwkbtV7zB90NLFHxo9ZqHgYAE8by+ylv/Yw9Muz9nKW8X8lA RWK1mF5L0MvPl8qLl9z0a1W0IZBUHwa81v7Z/rfSVjLEL7FZ0nhWMNQS4OcUbXb69Vyv tYAWhNaEGx/tJNTGOVKNN4sgGCfme8ikmF5vSteBLnjbdhcB6sjVoeS7ZKVIsFhDXD92 02YOWomZ76COswgRhL9dRSkmRbi3VWUOzJFvue0Y8Yt8Zvv6Ax0mhJAuklWG1nXioXGw Voig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701189625; x=1701794425; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XmTesqK+F/QJOwGcug6iguQ/D1cpFRALPok0GTAiegc=; b=T1g40vl8MtnZ8sCUkCd7oGtI+4kl6tf2I8FCrr6KT2inXm8wWzGRpTJsyVyp5L5ar6 K+kMagzs8Ag88tOfEhlPRWMKr2fLPeEaHNVwl1vw4zP7R9tLzb5QxG5w3aIKkUWajhVW v3kZwZzKB9+ypVJxiEXziEFTB+l3xFFBgKVS7AekHhsgiCFmFHc8WOO2kmfk5jVaLRim 6yS2pobibdie/A6N6eP6609kymLqAhdhlx74i/yK0Q8BSaydiy8zIKgLGeRIW7MgRuF9 ans9oxf7PDLcT/QY4mRtBsMhm120LuJHH54fIlle8R75NHGCQYrFiK/ebjT2MAngrNoI zZlg== X-Gm-Message-State: AOJu0YxDlXkO3k9K2QR9mME8ASl2/78TiaTs74xQEzCa/2N2DStkdLzZ zms+pREja44dL025B6cHaXVoDOvQGdxeUv5rxYjZvGX0lqyr0mru X-Received: by 2002:a05:6358:9394:b0:16d:fe28:f8cc with SMTP id h20-20020a056358939400b0016dfe28f8ccmr17146875rwb.4.1701189624933; Tue, 28 Nov 2023 08:40:24 -0800 (PST) MIME-Version: 1.0 References: <20231127193716.63143-1-brgl@bgdev.pl> <20231127193716.63143-2-brgl@bgdev.pl> In-Reply-To: From: Bartosz Golaszewski Date: Tue, 28 Nov 2023 17:40:13 +0100 Message-ID: Subject: Re: [PATCH 2/2] gpio: use a mutex to protect the list of GPIO devices To: Andy Shevchenko Cc: Linus Walleij , Kent Gibson , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email 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 (pete.vger.email [0.0.0.0]); Tue, 28 Nov 2023 08:40:37 -0800 (PST) On Tue, Nov 28, 2023 at 5:09=E2=80=AFPM Andy Shevchenko wrote: > > 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? > But that would mean more churn. I don't get why you insist on splitting these everytime. We're going from spinlock to a mutex so we may as well use guards right away. > > + /* > > + * TODO: this allocates a Linux GPIO number base in the g= lobal > > + * GPIO numberspace for this chip. In the long run we wan= t to > > + * get *rid* of this numberspace and use only descriptors= , but > > + * it may be a pipe dream. It will not happen before we g= et rid > > + * of the sysfs interface anyways. > > + */ > > ... > > > list_for_each_entry(gdev, &gpio_devices, list) > > + if (index-- =3D=3D 0) > > return gdev; > > I believe this is better with outer {}. > Right. Bart > -- > With Best Regards, > Andy Shevchenko > >