From patchwork Wed Nov 29 14:24:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 171376 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a5a7:0:b0:403:3b70:6f57 with SMTP id d7csp373573vqn; Wed, 29 Nov 2023 06:24:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IHT+krTmavurnA9h36CC52y23oTzGBZ4YNkXRqY/3eJSrN12G7cOh/BRrDu5y+FkdT4zadM X-Received: by 2002:a17:902:e5c6:b0:1cf:de3e:e4ca with SMTP id u6-20020a170902e5c600b001cfde3ee4camr10856627plf.20.1701267874353; Wed, 29 Nov 2023 06:24:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701267874; cv=none; d=google.com; s=arc-20160816; b=J2uS2cgYWLSI87XITfgZrs6wjZwiT/y7/Y5dsvJ1lYVNYLgVwFCdlipzgaqrw97zB6 UP6u992J/L7dynEgQbs5AqyAjdWVx36nBIPZmjqdDwnhXxr34k54qKKBII99blyaJoSf 8kPLFT6D/ahwMZ7mTtRyMhjRnJRaQ6BHLkhf3gt6Kabp6N3MLrTSjuZW8E4xFNlfOX0Y sB6Z0HpOEccp+kiavjae63QwvloycPKXpKpF5pa+JiDOV5UcAMob3Puuuco0Qn4MIb3p XqL4iQ1JlHiZDJnQAZeZn2JnYrcTHRpwcVP6tlWKqEsQt5w+R8bS3IsT9n2rmNTBjsge kgEA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=W2vlGJhIze8sK7FhkyHeBLiiHYWZ044RLoNjc90UYtQ=; fh=fw6biwzn34ngIUS3OuPB+D+TvAzoz1YwnvitHxA+Jyw=; b=P1wfuluGyUQ4X/MAXRxiTj3jzg7WVaqzbPYTei1d2+blb6ytooH4sp6efpe1zwMeKb gWPLZ26UEPGnSFONwByEw0eByWr3qEK9d5QzYdVHXeY607hkXaPRUqieK58Km2JUbdNV ZJccRHc0ouTAw4hyyxrLCmhlMP7e7XrpaIsCC7seG9y9lfgyW8yKdtZ6gCVoOZkIqJ5U 1AHbClBHb2vscLfZ9zW5T/FVmxEsSkih5yuLkV3oTWN9HxsZDjdAwPueXc++ZAm68dov dFFrPDlNpvIzGFf/etSd/gn1F3xdB2Fl1uTeXQVZDoxhSttnjYX62JfEdjg7n/HO3dn+ BQ9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=crqE15JI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id u11-20020a170902e5cb00b001d0029879d0si3166471plf.407.2023.11.29.06.24.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 06:24:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=crqE15JI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 9705080309BA; Wed, 29 Nov 2023 06:24:32 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234250AbjK2OYU (ORCPT + 99 others); Wed, 29 Nov 2023 09:24:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230487AbjK2OYS (ORCPT ); Wed, 29 Nov 2023 09:24:18 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 960FA197 for ; Wed, 29 Nov 2023 06:24:24 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-40b479ec4a3so25776285e9.2 for ; Wed, 29 Nov 2023 06:24:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1701267863; x=1701872663; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=W2vlGJhIze8sK7FhkyHeBLiiHYWZ044RLoNjc90UYtQ=; b=crqE15JIivDRD7HPz9UTlXpZe8y6b3M0VcIyqiQVPCgE+EgTIuWAAjCRr8hdm5pIg5 LHoZXe1ssMuLx7Ib1ksYYzD+7ipHUTZ5LLmpuHpWIPkRiHs8g37qiPeMtNq7RHJBCPKw tPR08+j7Do9gwDUkDi811MWKlE8nHUteE6W4Ge5vzYAqz4oq6wYHQ/72e10JG3Sct41s ldeGuzNoJcUmac9UgntzSZyvTGFoAAnluth+IO8yOUd9DSWbog4GOJ8EGEruztwtgDYl Vip9o8zX5WiBDZzdVkzV9cE1wouOKid3FvHM7Gikn4WG3gvPx5xhrdR5IjBsHxxofJb0 IXfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701267863; x=1701872663; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W2vlGJhIze8sK7FhkyHeBLiiHYWZ044RLoNjc90UYtQ=; b=mPjt7YxcMJFAgsnpa8WHvt20YBfiaPW2LiGjA30BRfvtg2xND8Cbe5BArXXCw1OOlM Rq8ahAt83fcFVH57c0InYsS5oVtRZ/HRm3iBlEbNWrx7v8M3HDFwr4e67VAAOfntm6AF NKOoNQggJ+SwYvbI52e8oa2Tc/2vHtQh1isp2PjxQiqWLlbMAbMZf30iK7M/22kNE16k R1XZBixD+pmdIInv09a1WjqkII2I2RzQI62AjcHvS4bI68DZtWczEruaqhge6ixEmTOL B/LJDYN3BvjDLHMYLGaDhZhZXpSUtL7zP3zpOC2GQs38A8MLXS/OH4V/F6CtOEPRZgeP o0bQ== X-Gm-Message-State: AOJu0YyglRKwzznNLgwXsgwUCzDD3RbyLSKKVAR0vC5CCCgz3kIqcl6v mFRgvj4lyjwahZ7A5HWerm1iig== X-Received: by 2002:a05:600c:3510:b0:40b:45e2:1f56 with SMTP id h16-20020a05600c351000b0040b45e21f56mr6396343wmq.39.1701267862985; Wed, 29 Nov 2023 06:24:22 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:4520:2f25:4d3a:4adf]) by smtp.gmail.com with ESMTPSA id n40-20020a05600c3ba800b0040b34720206sm2406848wms.12.2023.11.29.06.24.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 06:24:22 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 01/10] gpiolib: provide gpiochip_dup_line_label() Date: Wed, 29 Nov 2023 15:24:02 +0100 Message-Id: <20231129142411.76863-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231129142411.76863-1-brgl@bgdev.pl> References: <20231129142411.76863-1-brgl@bgdev.pl> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE, 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 lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 29 Nov 2023 06:24:32 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783908662587746957 X-GMAIL-MSGID: 1783908662587746957 From: Bartosz Golaszewski gpiochip_is_requested() not only has a misleading name but it returns a pointer to a string that is freed when the descriptor is released. Provide a new helper meant to replace it, which returns a copy of the label string instead. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib.c | 29 +++++++++++++++++++++++++++++ include/linux/gpio/driver.h | 1 + 2 files changed, 30 insertions(+) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index a5faaea6915d..8e932e6a6a8d 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2400,6 +2400,35 @@ const char *gpiochip_is_requested(struct gpio_chip *gc, unsigned int offset) } EXPORT_SYMBOL_GPL(gpiochip_is_requested); +/** + * gpiochip_dup_line_label - Get a copy of the consumer label. + * @gc: GPIO chip controlling this line. + * @offset: Hardware offset of the line. + * + * Returns: + * Pointer to a copy of the consumer label if the line is requested or NULL + * if it's not. If a valid pointer was returned, it must be freed using + * kfree(). In case of a memory allocation error, the function returns %ENOMEM. + * + * Must not be called from atomic context. + */ +char *gpiochip_dup_line_label(struct gpio_chip *gc, unsigned int offset) +{ + const char *label; + char *cpy; + + label = gpiochip_is_requested(gc, offset); + if (!label) + return NULL; + + cpy = kstrdup(label, GFP_KERNEL); + if (!cpy) + return ERR_PTR(-ENOMEM); + + return cpy; +} +EXPORT_SYMBOL_GPL(gpiochip_dup_line_label); + /** * gpiochip_request_own_desc - Allow GPIO chip to request its own descriptor * @gc: GPIO chip diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index 100c329dc986..9796a34e2fee 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -532,6 +532,7 @@ struct gpio_chip { }; const char *gpiochip_is_requested(struct gpio_chip *gc, unsigned int offset); +char *gpiochip_dup_line_label(struct gpio_chip *gc, unsigned int offset); /** * for_each_requested_gpio_in_range - iterates over requested GPIOs in a given range