From nobody Thu Nov 28 05:52:24 2024 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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 891AC21B44F for ; Fri, 4 Oct 2024 14:43:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728053021; cv=none; b=NRdgnrzh8ihuhppaHScjADthJyQRfJpeR1iogok6DwHPZlHzbmkEKvNn+1kJkpE7z7wlztwgE6yR1fmkJn2vgKEb5BloynPMHbor/LW8eJW0IWROuwtzZmva7uXTB+IEolRfxcxESxrxI90tEFQlP6kPs1F2sdP2g2QF1WguWOA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728053021; c=relaxed/simple; bh=nILLEVrSRUMuX39lz3JI49M+Jl9a8uMyMqPKy0crlCE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ECE+5pYEicZeBgpdyCSzf/YlFHiNqnj22xrX7fnan+ftzYhSljw+BnmAc8ZtB/SHLrO11bK9aVZpy8yMKimYKasV5FeLn/0A/SfltJApdyAkxVPXIepNkVb2yCYY7de4TSgRaGVsY5566wi0I1NDdRL0UKkOIMa2w9Az/B1cFVM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=EItN/f4B; arc=none smtp.client-ip=209.85.221.53 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 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="EItN/f4B" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-37ccc597b96so1494082f8f.3 for ; Fri, 04 Oct 2024 07:43:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1728053017; x=1728657817; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=7vd/1ALFEEqvJdDJR8cRrUppctjGlEDDTBM1Pkd8mDw=; b=EItN/f4BbjUFjWx0V+78y3vY59KMvFPWzPr+qKXhzXKH9+LlFmXX7y3S5bnObewRlv vw242fLULvAlHWZ3OhoQHUEfyO8MogUdw1p6X+7J5Yi00VC3Syu/PngG7po/1Xm3ueC/ KyfjsMdLap1cpOIykTzOW4r5GHCETwSS9ejvGjGsxBGRT1iDNAR5bv6LaPj1a48BY3v/ r1FhjscJPIf2xoWwqY/ZxLfjSdmof2ifWpnWSbk8tpRPIWb9PZCXjSXVVKhfj6tzoVpz PSMnHWxT4FBqqH9QPnQ73xCDBRsL4AVePdVyywhGjish80/WzWnIVY1N+CnLj7KGCpt2 c6Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728053017; x=1728657817; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7vd/1ALFEEqvJdDJR8cRrUppctjGlEDDTBM1Pkd8mDw=; b=taPDV5LuCWDQZ5HfuDwW53WwsGiZJ2cm2cW6RK/z3sVB7SxLtDs/n36wSlyHIfw1eq UYJBUQBCkE1MywZfwvNvxjyI7sAd+0W3+aIs7lZtt9C9CifGgdfJYF1sObcW3xjXSWTF FyxqqdlgklphS37C4JJjYiZr2u3wITQR2vHUi+0soxcF7xvr3mkx+BBvoOHFCT8ctDPQ Z1evM5xi/nd12eRGPtevjoJW8r5LWHFzqCE47oERSjZm9F1Bt+18/d8nWnhb8LRiTcv1 WSlHicIMgGCjYeTUeXzS8+RjaWU7JTunQRSVjQi/qCsCIZDPuufIHX/17P5EmNVO/3A5 2mYw== X-Forwarded-Encrypted: i=1; AJvYcCWxTZYw/3qqHPUa5+GmL9D7moMor9uj8u/WfvJjl93NZRg6DJYlym2gpkSTua8tte6YFA7V1Q+rXznvbSA=@vger.kernel.org X-Gm-Message-State: AOJu0YzYhuR3kr+jQYzEl9meaYrO35MwyO12GSV+1nQ+8r5bxbJBehG1 7If6j14f/Xa3zOdLcx4ZXMpVLM2E6jjrxnXYRJXFDKQ4aVdYF9EN0hMt5GFG2oI= X-Google-Smtp-Source: AGHT+IFOlwf1L/29DI0sE6sorIwM4sUuGpUATmRbKu+GBttC3o9DZIPg8ltKyasMoo4j0Kx5Yx9quQ== X-Received: by 2002:adf:f00a:0:b0:374:c3a3:1f4f with SMTP id ffacd0b85a97d-37d0e76fdf2mr2048119f8f.24.1728053017382; Fri, 04 Oct 2024 07:43:37 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:80ea:d045:eb77:2d3b]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d082d20bcsm3361370f8f.100.2024.10.04.07.43.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Oct 2024 07:43:36 -0700 (PDT) From: Bartosz Golaszewski Date: Fri, 04 Oct 2024 16:43:24 +0200 Subject: [PATCH 3/5] gpio: cdev: update flags at once when reconfiguring from user-space Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241004-gpio-notify-in-kernel-events-v1-3-8ac29e1df4fe@linaro.org> References: <20241004-gpio-notify-in-kernel-events-v1-0-8ac29e1df4fe@linaro.org> In-Reply-To: <20241004-gpio-notify-in-kernel-events-v1-0-8ac29e1df4fe@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4291; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=ki9bnqoP0GYF3msoNU816SMbodAflXGpvokYWavz7z0=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBm//8VT5dAQQkkclXy52MS05gZoxyh4AYz3vXS/ UATzlpaS5CJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZv//FQAKCRARpy6gFHHX cjdGD/4+BHr0wq0zQIbMTrE1Eou3YpR0GQ6BZUcqFZERUcQuTYuRFR1kPDR5Cu3MkzhsZzM0Zlj gNqVo7YLSOSnxigxPMLM/xreqSkPdQymbxDIFGw6xnbd34+tNAlj3a9L0dagOAcJsS1d8heMnF4 dbEz1ZcDjgoEV+xJMzI5uIIrqxEOV6lJfnLSSUzvDFKPDJ0VjTl65H3zidrTzHS+Emob0YdH7QP kWL3GgRuM9YEh8W859HGLYaEYV/HaI++C9h8rFb4Sk5+B2iPgFKRCXwoUGd5LBJxh2Ju7G46faF TemMrKEId23sslmQKBrE1idevshk5kIbufaZHvT/EnUa+NOEupeQ8GdfkdXnNrfz2yKHmuVjYIX dGoO5+x11gX4S7KXmS2WQugAK2hQjBWhBzaTl+5r55kDT24m5qFfHTvIduByU7hOJS2wgOy7g8d +yIwGfkpCxD6GoM1X1yU0YnuysWe/U1ps8ew+eJGvffBSRVwVHx5N+LF/DogBjq9xwr+k5wyCLn 3vlRZQofvmJwWKBZK/K7MbwXRSzJkkoY/MGBgVKqZRib9QPr86vZ9OQSUbCnMNMqj9iz+xE10Sj XI3o6mNb+x4GMzEv4Fjp56Vjh5epTPmMTwyMZseibo+AWTPhtVIbpMuH1UjPMn26GrQIN7DFBhJ 6ph4KijIn6hF9Og== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski Make updating the descriptor flags when reconfiguring from user-space consistent with the rest of the codebase: read the current state atomically, update it according to user's instructions and write it back atomically as well. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-cdev.c | 70 +++++++++++++++++++++++++----------------= ---- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 6113a283c34a..b0050250ac3a 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -143,18 +143,22 @@ static int linehandle_validate_flags(u32 flags) =20 static void linehandle_flags_to_desc_flags(u32 lflags, unsigned long *flag= sp) { - assign_bit(FLAG_ACTIVE_LOW, flagsp, + unsigned long flags =3D READ_ONCE(*flagsp); + + assign_bit(FLAG_ACTIVE_LOW, &flags, lflags & GPIOHANDLE_REQUEST_ACTIVE_LOW); - assign_bit(FLAG_OPEN_DRAIN, flagsp, + assign_bit(FLAG_OPEN_DRAIN, &flags, lflags & GPIOHANDLE_REQUEST_OPEN_DRAIN); - assign_bit(FLAG_OPEN_SOURCE, flagsp, + assign_bit(FLAG_OPEN_SOURCE, &flags, lflags & GPIOHANDLE_REQUEST_OPEN_SOURCE); - assign_bit(FLAG_PULL_UP, flagsp, + assign_bit(FLAG_PULL_UP, &flags, lflags & GPIOHANDLE_REQUEST_BIAS_PULL_UP); - assign_bit(FLAG_PULL_DOWN, flagsp, + assign_bit(FLAG_PULL_DOWN, &flags, lflags & GPIOHANDLE_REQUEST_BIAS_PULL_DOWN); - assign_bit(FLAG_BIAS_DISABLE, flagsp, + assign_bit(FLAG_BIAS_DISABLE, &flags, lflags & GPIOHANDLE_REQUEST_BIAS_DISABLE); + + WRITE_ONCE(*flagsp, flags); } =20 static long linehandle_set_config(struct linehandle_state *lh, @@ -1348,38 +1352,42 @@ static int gpio_v2_line_config_validate(struct gpio= _v2_line_config *lc, return 0; } =20 -static void gpio_v2_line_config_flags_to_desc_flags(u64 flags, +static void gpio_v2_line_config_flags_to_desc_flags(u64 lflags, unsigned long *flagsp) { - assign_bit(FLAG_ACTIVE_LOW, flagsp, - flags & GPIO_V2_LINE_FLAG_ACTIVE_LOW); + unsigned long flags =3D READ_ONCE(*flagsp); =20 - if (flags & GPIO_V2_LINE_FLAG_OUTPUT) - set_bit(FLAG_IS_OUT, flagsp); - else if (flags & GPIO_V2_LINE_FLAG_INPUT) - clear_bit(FLAG_IS_OUT, flagsp); + assign_bit(FLAG_ACTIVE_LOW, &flags, + lflags & GPIO_V2_LINE_FLAG_ACTIVE_LOW); =20 - assign_bit(FLAG_EDGE_RISING, flagsp, - flags & GPIO_V2_LINE_FLAG_EDGE_RISING); - assign_bit(FLAG_EDGE_FALLING, flagsp, - flags & GPIO_V2_LINE_FLAG_EDGE_FALLING); + if (lflags & GPIO_V2_LINE_FLAG_OUTPUT) + set_bit(FLAG_IS_OUT, &flags); + else if (lflags & GPIO_V2_LINE_FLAG_INPUT) + clear_bit(FLAG_IS_OUT, &flags); =20 - assign_bit(FLAG_OPEN_DRAIN, flagsp, - flags & GPIO_V2_LINE_FLAG_OPEN_DRAIN); - assign_bit(FLAG_OPEN_SOURCE, flagsp, - flags & GPIO_V2_LINE_FLAG_OPEN_SOURCE); + assign_bit(FLAG_EDGE_RISING, &flags, + lflags & GPIO_V2_LINE_FLAG_EDGE_RISING); + assign_bit(FLAG_EDGE_FALLING, &flags, + lflags & GPIO_V2_LINE_FLAG_EDGE_FALLING); =20 - assign_bit(FLAG_PULL_UP, flagsp, - flags & GPIO_V2_LINE_FLAG_BIAS_PULL_UP); - assign_bit(FLAG_PULL_DOWN, flagsp, - flags & GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN); - assign_bit(FLAG_BIAS_DISABLE, flagsp, - flags & GPIO_V2_LINE_FLAG_BIAS_DISABLED); + assign_bit(FLAG_OPEN_DRAIN, &flags, + lflags & GPIO_V2_LINE_FLAG_OPEN_DRAIN); + assign_bit(FLAG_OPEN_SOURCE, &flags, + lflags & GPIO_V2_LINE_FLAG_OPEN_SOURCE); =20 - assign_bit(FLAG_EVENT_CLOCK_REALTIME, flagsp, - flags & GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME); - assign_bit(FLAG_EVENT_CLOCK_HTE, flagsp, - flags & GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE); + assign_bit(FLAG_PULL_UP, &flags, + lflags & GPIO_V2_LINE_FLAG_BIAS_PULL_UP); + assign_bit(FLAG_PULL_DOWN, &flags, + lflags & GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN); + assign_bit(FLAG_BIAS_DISABLE, &flags, + lflags & GPIO_V2_LINE_FLAG_BIAS_DISABLED); + + assign_bit(FLAG_EVENT_CLOCK_REALTIME, &flags, + lflags & GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME); + assign_bit(FLAG_EVENT_CLOCK_HTE, &flags, + lflags & GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE); + + WRITE_ONCE(*flagsp, flags); } =20 static long linereq_get_values(struct linereq *lr, void __user *ip) --=20 2.43.0