Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6762362rdb; Fri, 15 Dec 2023 07:44:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IEOtW+b8UfUHfI3bF0OeRutCHQ+ZXCHNWMQ2hB88JfRoBkj8JpgKJUOvjfVx/mwwM34drH7 X-Received: by 2002:ac8:5f8b:0:b0:423:8b1a:67e7 with SMTP id j11-20020ac85f8b000000b004238b1a67e7mr18491219qta.42.1702655051394; Fri, 15 Dec 2023 07:44:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702655051; cv=none; d=google.com; s=arc-20160816; b=lLNIwn7b83KQmYUq5urmFMy1KZP6TyhhVRRfEChKE7DVBjZ0LEidJBiBiunF/lsc8g RAyL1K3gsC1tXyG5Zu0eXHn3k3ycKKxdu57SpmADGbMTWQ1HG81CS+ppMWtgbZ71IiNs kmDy/u+MSloD2wTH8PO4jZOdngNxNCzdy5yb0wnF5dnf7bbQJfpu+oURZpC68pdK4KKo MjLOXNvrXLr8TTG8m4+jT9vRKlXIxlbXdxA5xrRZq333uGzZ7XTPLhJTHpOEj90gz6+s GMnxwRgBvLvyE2eon6dg4QtOSkCxspB56mEGk5X39inRsGzMjrw6+gsmc1UfrcxO2kmn rM4w== 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=j7aJHSr2v0aXZU02xkacVR4ZEcIVwOeki7KFEoLbvYY=; fh=Ad8g5eWxOTSy0OIuRVCFvHLgF3L87MCa94q6cbQRjqo=; b=lwZnK9kfjUGPMtRAgUdtzSY3HT2gyzrFssnZvapzNdLoM6+oadnOIXgOljS66L30vq qs1mVqpRcbMYedrZOJeSihibm2PbY24fedr7JAO+/ph/Wwaee4KylDAsxCEE+XtNgcdD Fpc3V1MmuupyvXf3R2AG0W04w7L0mTg2W+EbWO6Nlw+runtSAT5RHgkGiF3E7akfYnRv /WWJgBeYVrJsUxBVFRNVleM+OhjRtBFQlK6iCfpaeIm1rmhM62D8iiD+VHX0xGBgFToG bHQOLuRf5fi4iJ5sCUgD+637brcjyEmEXdg8bKqUl7ew3HwyczZj0FRzgYMPJmXKnnf2 2G0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b="H0mwJ/iU"; spf=pass (google.com: domain of linux-kernel+bounces-1225-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1225-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id s7-20020a05622a178700b0042575b1269asi19238614qtk.458.2023.12.15.07.44.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 07:44:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1225-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b="H0mwJ/iU"; spf=pass (google.com: domain of linux-kernel+bounces-1225-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1225-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 29A091C211B2 for ; Fri, 15 Dec 2023 15:44:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D5C42381AB; Fri, 15 Dec 2023 15:44:05 +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="H0mwJ/iU" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-oi1-f177.google.com (mail-oi1-f177.google.com [209.85.167.177]) (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 E7EB837163 for ; Fri, 15 Dec 2023 15:44:02 +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-oi1-f177.google.com with SMTP id 5614622812f47-3b9dc3215d2so380364b6e.0 for ; Fri, 15 Dec 2023 07:44:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1702655042; x=1703259842; 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=j7aJHSr2v0aXZU02xkacVR4ZEcIVwOeki7KFEoLbvYY=; b=H0mwJ/iUmraKTz/xal39Z/DhCVEsKZ26v9lrokF2n3J8z0uQIAiPPEldQ65gEypC0b dIRZFAWrPtpzNzw/BfJpW/brxHHlL8N/WvX9PJ7Y9KYW/LPj5Jg1xwG89O3TXvwGhk7j iUDa+t0KHQFMIGJFiiJRmLvBh6OGUSq7dD8tF7ahVSvo/NXasa4SxokeMv6fCD0HSQFL NLMWkWKL/uCRs3MShdKlHMZ+RB3cZW/VziZeLuwWVeUpQPVtnBVOhDNhUSoQklP7jtAT juJda2ZT4o4T2wRHNY+wVo7CGdQX0osx14BEs4LN0DmZba5Qegumrq8ukvlrcQUFg+pe LvWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702655042; x=1703259842; 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=j7aJHSr2v0aXZU02xkacVR4ZEcIVwOeki7KFEoLbvYY=; b=riI5YZszH9vRolvpV5iqxf9OPTetW8ICCQta9yVtvqTwhLRnJV9MjP9CqgzkXyKkGp Nnf0OuV/9QHdel4aVG3XzTDCt2QIjXrHSLQo8NNJ+gjLlnV/WA1roPytxHby/6WH4aBN pZoxx4zA2jgiI7ybCK6foRoNO+0kAZ0ttq7eNrHEu6y2dqGGWcTDRZSRlfiBqer2Tn/Q V3RoLeAyd/ZKV0C5Jvvkj0k5NmFzWaRuTQa4twOxZo1qf5iQ9tkvlEww1mttvbBS01iN /qtTyPrLQ48S2eO17N3IxvuY+ByjZaC7NyLQepGRG3vUbcl1zfbJkaAqJgBwkL8Eyj+B Fsbw== X-Gm-Message-State: AOJu0Yy+eYZPvD1LyC3SrdNsgQcQJN0rABH/rS92CfItVXMdFOFh3wYU QfMOzRQLiRt35o5jcbcwbfNrN+CdaxGgwaFtO6Nfeg== X-Received: by 2002:a05:6808:448c:b0:3b8:632e:a83c with SMTP id eq12-20020a056808448c00b003b8632ea83cmr13794717oib.17.1702655042017; Fri, 15 Dec 2023 07:44:02 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231212105501.16347-1-brgl@bgdev.pl> In-Reply-To: <20231212105501.16347-1-brgl@bgdev.pl> From: Bartosz Golaszewski Date: Fri, 15 Dec 2023 16:43:50 +0100 Message-ID: Subject: Re: [PATCH] gpiolib: allocate memory atomically with a spinlock held To: Linus Walleij , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski , Dan Carpenter Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Dec 12, 2023 at 11:55=E2=80=AFAM Bartosz Golaszewski wrote: > > From: Bartosz Golaszewski > > We will eventually switch to protecting the GPIO descriptors with a mutex > but until then, we need to allocate memory for the label copy atomically > while we're holding the global spinlock. > > Reported-by: Dan Carpenter > Closes: https://lore.kernel.org/linux-gpio/62588146-eed6-42f7-ba26-160226= b109fe@moroto.mountain/T/#u > Fixes: f8d05e276b45 ("gpiolib: remove gpiochip_is_requested()") > Signed-off-by: Bartosz Golaszewski > --- > drivers/gpio/gpiolib.c | 10 +++++++++- > 1 file changed, 9 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c > index 4e190be75dc2..6efe44570333 100644 > --- a/drivers/gpio/gpiolib.c > +++ b/drivers/gpio/gpiolib.c > @@ -2399,7 +2399,15 @@ char *gpiochip_dup_line_label(struct gpio_chip *gc= , unsigned int offset) > if (!test_bit(FLAG_REQUESTED, &desc->flags)) > return NULL; > > - label =3D kstrdup(desc->label, GFP_KERNEL); > + /* > + * FIXME: Once we mark gpiod_direction_input/output() and > + * gpiod_get_direction() with might_sleep(), we'll be able to pro= tect > + * the GPIO descriptors with mutex (while value setting operation= s will > + * become lockless). > + * > + * Until this happens, this allocation needs to be atomic. > + */ > + label =3D kstrdup(desc->label, GFP_ATOMIC); > if (!label) > return ERR_PTR(-ENOMEM); > > -- > 2.40.1 > Patch applied. Bart