Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4552103rdb; Tue, 12 Dec 2023 02:56:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IErF92GHg71SnHLTWSkOiEbtPXa9941Hqzv8Xy5JI2c7Cjfqh90VZFmSMoGbrb8ni91aFTR X-Received: by 2002:aa7:8586:0:b0:6ce:f651:283f with SMTP id w6-20020aa78586000000b006cef651283fmr1837852pfn.25.1702378566884; Tue, 12 Dec 2023 02:56:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702378566; cv=none; d=google.com; s=arc-20160816; b=pTuzWH0p35os+u09HhNEGrQOmC9a4xVO0K5613AEBqSiq0EDJVfKWbay3Hmd+yEKEu yuljTioenGziCcv2WFB3lCsw4MdyMqiDMrkbDkuocJRvy/wdPOnAkkKki3aQNkH49Gab G3g/dLVzbpfGvVQa4OssztfyqO4LbL2uWCCETFXv8UqE+Z6xT2smOCz+2Ikrl9ipfAxt nfXGP3LqzoKXFvet1nJrqH4ASA8iqhrOYDTdd36OBW7VHav7LaK7fV53RJyviO7qRHh5 74MOAa4tgOpC+WrF3vdi89VmDTs0X68goM7f7o2u+wO2eh7XtUbGLk7oeClPQgakQ9w+ MHLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=l0Xt7zxPEL8s4LsBKOkLuKnVLrdFFEGGYWcjy48Nb20=; fh=Ad8g5eWxOTSy0OIuRVCFvHLgF3L87MCa94q6cbQRjqo=; b=p/OtlCbjdN1cEFvukyAZSUj1FczVDEbOCysM2YfQZHaKtEhxzdGVqbRJwfPA5tXs09 3cZapjI33a8tRG1anedzxajLYfoludSU5HEM9ExOyCfu2rc4Hf+OU8tdyG8jE/Bt0LMF AxGn8rL/rnbFLXAcfhqUF6lskRiA4Z/vzdshzrG7dgC7vT1P24ni/sbv9ESieKv37Fb/ Ep+uCoXLPJLP1tGEaiKHqxTjSS9TNQfSmbBmAmfSQGdZzr+VsryWMYy0gp0xBkCcgtTv uGQAeC/mfY6aNELGnKmTOUOX3AEhsrpgIO4znl+zDE8vwOmooX2HsHEPCuyGAahJF2Wh wuDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=JVM4mkS1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id u13-20020a62d44d000000b006cdeb7e9f6dsi7308383pfl.234.2023.12.12.02.55.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 02:56:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=JVM4mkS1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id BBC91807C74A; Tue, 12 Dec 2023 02:55:22 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231543AbjLLKzC (ORCPT + 99 others); Tue, 12 Dec 2023 05:55:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229379AbjLLKzB (ORCPT ); Tue, 12 Dec 2023 05:55:01 -0500 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 195B0A0 for ; Tue, 12 Dec 2023 02:55:07 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-40c236624edso55750655e9.1 for ; Tue, 12 Dec 2023 02:55:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1702378505; x=1702983305; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=l0Xt7zxPEL8s4LsBKOkLuKnVLrdFFEGGYWcjy48Nb20=; b=JVM4mkS1YAMWnOSQTT49O9Bm9F9UWfXqhTQZg8okXqblVsqO0hb+FqrQSrSlh/B1CF tcDnaa9LRx7NGGTkdu7xNJnQxq75Kz1uqnkGV5cb8Sdt28zCsYB8OLr3LT1mW3NEdhrR rS84w1fqVxeg85NVgqjVhqHI6LKm5CZw/JdM4KFNyC5MAUYiy6H5d3BIgltnbQrjHfIx s0ToHjRgCHIx1oWtiiwVTtRF4GWPTz0+EH//kkzZQL+X9A6eZw/HbdUYDStRVrpBbmgj am6W/zuBnEIUPyBoMFgEnm0eDgOd7wgG6yj4A5TD1NsS/VA7bGlA5+cGNhfg+g+Z5scs Ssmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702378505; x=1702983305; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=l0Xt7zxPEL8s4LsBKOkLuKnVLrdFFEGGYWcjy48Nb20=; b=xE0y8+8lH80SsZk1QCFqXDPEIvA9kpBvyTfxdzJAuPwOigRKGH99HzVFg2mclUXUaW xPjFHdGRR97YDTSrpN12MBppdzH86AiW5YjMRwXRyN4PM5NeNzANGk4vFJZn0dCDtf6o Lrp8cQ45vXgnDUKfKYLsxuJQkV4EIwnzLHGg9kwAKoJZTK7FauB1ZhRSqTtD5RYCDg4S xPcvXDm16Hi/5mOP7taFF1Pf71pUvJUWlgmiFrpF69Fac0KOMGXwiT72v+uLs9+nIpjF viwUmLlfCR/xkxuyfaVmu9lbM5wiuvzYQRu21YobPXyC2mpBLGpnHXxWMiCQIwOEdlYS U93Q== X-Gm-Message-State: AOJu0YxsHYxudcK9tv2RW82UEeWerXCbmF4yp3V4civBAJZ/LhTR0TIK hGe5ELCGrzyaZ6RvWCIfjji6WFG953nqY9fgqaA= X-Received: by 2002:a05:600c:358c:b0:40c:2a41:4a3c with SMTP id p12-20020a05600c358c00b0040c2a414a3cmr2892381wmq.146.1702378505435; Tue, 12 Dec 2023 02:55:05 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:1012:9edc:5109:e70f]) by smtp.gmail.com with ESMTPSA id c4-20020adffb44000000b003362d0eefd3sm1132122wrs.20.2023.12.12.02.55.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 02:55:04 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski , Dan Carpenter Subject: [PATCH] gpiolib: allocate memory atomically with a spinlock held Date: Tue, 12 Dec 2023 11:55:01 +0100 Message-Id: <20231212105501.16347-1-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 morse.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 (morse.vger.email [0.0.0.0]); Tue, 12 Dec 2023 02:55:22 -0800 (PST) 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-160226b109fe@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 = 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 protect + * the GPIO descriptors with mutex (while value setting operations will + * become lockless). + * + * Until this happens, this allocation needs to be atomic. + */ + label = kstrdup(desc->label, GFP_ATOMIC); if (!label) return ERR_PTR(-ENOMEM); -- 2.40.1