Received: by 2002:ac8:5349:0:b0:427:7d78:cd45 with SMTP id d9csp813103qto; Wed, 20 Dec 2023 04:51:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IEvDbs5o9/x22FSvu3n0QEzbf6OV7HzmBssI23UDPDa4awie7C9ZzvBP6HciuXSRF/DXhyK X-Received: by 2002:a50:d5de:0:b0:553:1956:76d9 with SMTP id g30-20020a50d5de000000b00553195676d9mr3166726edj.10.1703076674684; Wed, 20 Dec 2023 04:51:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703076674; cv=none; d=google.com; s=arc-20160816; b=nckvVP5ZXXpbOuaI+bvM1g+EXJl4NnkSGHb63nQp0p2xxivFUl7QMfV65T62L12h7+ f1qe3RGZCTJOE6hXzsj5J1kAQeSKu9J4HGcA6idD/LuCAoP3myHgfHayNCkr8dJJXkO4 G6GxfGWZ/5CfzdM3zhtIqvR/oe/NIaWlUQX2Vx6eM0vTfKktKoKxzXacKHdPscO98UGF QJZ6lQcho2xFoqjHWGGlUuLgy0uJXwyD5mgyDSsCoDRJDJZ2L8/p1bzHYy5h/Oyo/Grq TDzu5iy5X1RrrcGpIBgoexbpDfnJV+ZRRqKTsZMTEq8tXG68+qHGCjLtwcvXwzIUsdXM bWBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=Smv/oTS6xzj2r1xVgNmv4h0iEnVC3n6WF5A+ikrNt/U=; fh=rzYCGcVzjQFPqkySNmUpcDHHUQRjal3ddModzuE5/FY=; b=SLtSWse1DENF3hV4UAB4nfIJVVK8fnCbPRKDUQdrDsxsn3pWq+VwnyK8X6eNGQqGSh GjrnVLVKM4lw1OTJCfzY/eWXS1Db4SjaDK73LVaJaE/ravWVNUfCusTr8/zSqtf9CafT t82CmOZOR06A+yy+9w5ox/6umbFYheYG6LjhqHWseZfbK4t14JNupKBkxxbqOTTQFN+8 JGkrjLu8dx4pAxvkz8AeE9rDHcwq3o+lAdMZ5txtN1TAtwVCSbLyXOg4g5lkP2Xdv0yz dWbDNuziHhIu1GCEbxb/QVffVQfBi9LDkWaP+VYmJyadoNcpXUAwjp/O2oPqtPQ1jC3F uW0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=qqcydmI4; spf=pass (google.com: domain of linux-kernel+bounces-6895-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6895-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id s1-20020a50ab01000000b00551e2c7190csi7497107edc.430.2023.12.20.04.51.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 04:51:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6895-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=qqcydmI4; spf=pass (google.com: domain of linux-kernel+bounces-6895-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6895-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 6C3491F27A29 for ; Wed, 20 Dec 2023 12:31:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0593624B35; Wed, 20 Dec 2023 12:31:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="qqcydmI4" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-vs1-f52.google.com (mail-vs1-f52.google.com [209.85.217.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DBE2324B25 for ; Wed, 20 Dec 2023 12:31:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Received: by mail-vs1-f52.google.com with SMTP id ada2fe7eead31-466afcc2e5dso365514137.3 for ; Wed, 20 Dec 2023 04:31:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1703075468; x=1703680268; 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=Smv/oTS6xzj2r1xVgNmv4h0iEnVC3n6WF5A+ikrNt/U=; b=qqcydmI4AeK9JjTT59wwwUv467Aph67TCM/HqMnUKZ2Jd3NZcElq/bi6nke5N+jObw 9M1OhE2JE1eQgXM1dbUIrfcfPTh0ftsJJWw/0aUkb/wwB4SkD8T+uTgpA0COB7Ux02Do Eeld/tFTPSeBqUAgHEaFRE13DsT7SXW1IQFOtCAMzPP0UbkvsnRAIE9tEMSM9CDrW2Ux tifFLgL+qQu1caQoQ6gdm1gdyPxcKlanyAfHMbVKGK2HqnRhuaX2MvUmp/Pxp172VkDz cxJgRu87bb9DpFZ9Kl4B9YXXh5K++U4VZ8Hy+QZewReSuZyfyy7noLuuNhr2u9D3c5Np hTvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703075468; x=1703680268; 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=Smv/oTS6xzj2r1xVgNmv4h0iEnVC3n6WF5A+ikrNt/U=; b=mw9vplYZM1RqKeLGI68/kotU01RdQ6lk9S1EHx6ZDOPR6c5P8bSYemxTqUiKSLiHZs vCH9yZfucDjBo8tRjgZra5WGsMLL2Zeuu+Ls5x5In10dJJL5q+LsfUMAAZmZrAZLlYb8 NJOY5fz9hftK5/HxVWGHwUzDrCiE+PRQsqj+V/mtB5IIjxGHTB0fMXxYobmNbUI5jX2q zi6tdbvI6y1krFx4gfph/BKdCkSViuKBm2Mq3K+2aBEutZdBz/mpguJnFOL1kdwd/KKA oEKp7jghJ+umYR/tV9DA2oaOIUxZrHBop6V4FRZU8latSx0JzOizdDIe7jlc5x/B3Iti t8/Q== X-Gm-Message-State: AOJu0Yw2OI4hH86Rvl8b+Pt8j9F7t5Lb+vkg1H5DGZcS+Mp3SRc1UQ+1 +e64KVQEQdnVCTwUUC+bg8/Hyet57otki0/Rfrb+AQ== X-Received: by 2002:a05:6102:559e:b0:466:a1a2:55a4 with SMTP id dc30-20020a056102559e00b00466a1a255a4mr3179934vsb.9.1703075468746; Wed, 20 Dec 2023 04:31:08 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231220015106.16732-1-warthog618@gmail.com> <20231220015106.16732-5-warthog618@gmail.com> In-Reply-To: From: Bartosz Golaszewski Date: Wed, 20 Dec 2023 13:30:57 +0100 Message-ID: Subject: Re: [PATCH 4/4] gpiolib: cdev: replace locking wrappers for gpio_device with guards To: Kent Gibson Cc: Linus Walleij , Peter Zijlstra , linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, andy@kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Dec 20, 2023 at 1:23=E2=80=AFPM Kent Gibson = wrote: > > On Wed, Dec 20, 2023 at 01:16:00PM +0100, Bartosz Golaszewski wrote: > > On Wed, Dec 20, 2023 at 1:13=E2=80=AFPM Kent Gibson wrote: > > > > > > On Wed, Dec 20, 2023 at 01:05:35PM +0100, Bartosz Golaszewski wrote: > > > > On Wed, Dec 20, 2023 at 12:56=E2=80=AFPM Linus Walleij wrote: > > > > > > > > > > (+PeterZ) > > > > > > > > > > On Wed, Dec 20, 2023 at 2:52=E2=80=AFAM Kent Gibson wrote: > > > > > > > > > > > Replace the wrapping functions that inhibit removal of the gpio= _device > > > > > > with equivalent guard macros. > > > > > > > > > > > > Signed-off-by: Kent Gibson > > > > > (...) > > > > > > +DEFINE_CLASS(_read_sem_guard, > > > > > > + struct rw_semaphore *, > > > > > > + up_read(_T), > > > > > > + ({ > > > > > > + down_read(sem); > > > > > > + sem; > > > > > > + }), > > > > > > + struct rw_semaphore *sem); > > > > > > > > > > Isn't this so generic that it should be in ? > > > > > > > > > > Otherwise all the patches look good to me. > > > > > > > > > > > > > We already have this: > > > > > > > > DEFINE_GUARD(rwsem_read, struct rw_semaphore *, down_read(_T), up_r= ead(_T)) > > > > DEFINE_GUARD(rwsem_write, struct rw_semaphore *, down_write(_T), up= _write(_T)) > > > > > > > > DEFINE_FREE(up_read, struct rw_semaphore *, if (_T) up_read(_T)) > > > > DEFINE_FREE(up_write, struct rw_semaphore *, if (_T) up_write(_T)) > > > > > > > > > > Ah - in rwsem.h - I missed that. > > > > > > > This can surely be used here, right? > > > > > > > > > > Don't see why not. > > > > > > I would still like to move the gpio_device specific macros to gpiolib= .h, > > > as they apply to the struct gpio_device defined there. > > > > Which ones? Because I'd rather use guard(rwsem_read)(&gdev->sem); than > > some custom wrapper as this one's purpose is clearer. > > > > It would be read and write guards for the gpio_device. > cdev would only be using the read flavour. > And possibly named something other than read/write as the purpose is to > prevent (read) or allow (write) object removal. > > I though that would be clearer than having to reference gpiolib.h to see > what gdev->sem covers, and allow you to change the locking > mechanism later and not have to update cdev. > I still prefer open-coded guards here for clarity. I hope that with SRCU in gpiolib.c, we'll get rid of locking in cdev entirely anyway. Bart > Cheers, > Kent. >