Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp2498820rdg; Mon, 14 Aug 2023 04:47:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHmqAg2lNkWCTraXMewBCR1TNQfW9rpZ7zqWt7eavmShXI5Ka9EEJjcUUqbkmfe3Y5AOv93 X-Received: by 2002:a05:6a21:271f:b0:140:d536:d428 with SMTP id rm31-20020a056a21271f00b00140d536d428mr7733105pzb.51.1692013647600; Mon, 14 Aug 2023 04:47:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692013647; cv=none; d=google.com; s=arc-20160816; b=IGqf+sa7qtqzndvgSoR+Mz8cjBtpN1eLiwcBXlWzZ1L9q24QXBgSPEmC+aj2LPRwa9 M9EZbeY4C5LCBxLMtie9vg2ByuaHakJhpG8jPruR2M7tW3hHhwviqIK34zO83EyVDa87 TN8JVAIEl4Smb8OwhKnPco8N22GtjQEqg9DcbeP/bulFKGippQqZo8GLTyUGPh7qjRQF iSZNHpQakrIP2jU/XtQplYRTy1i14eSzc5yTqHqM1mKQvC8W6leHPwxuinVTw3l0ZgIR JgbKv096kabjPuwQeTVaBU59I/K5PC3lfxCaw8Xnxwv1dDQZsqAwqmNbq2RU8Z0/ZhmZ L1Yw== 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=yw3frDe0JnDqDB4XyB/3KXDrpDFdt7iS4D5Q0Ak3UJk=; fh=O+xBE4t3Jd95fh6q/TAlvBvalFxBcNQNGW9Ftd0cahg=; b=T7GITtl7sU4DK1VRdZjKlU1OABAxmor0AH6wXJeegRw8ndFASqjixhhoPBpvgj1r8S 1xdJj3CR+HtMzre+//IHYRAiuBvi/RvCFYYwDWLBV1DxrLqL6O0wcUxZHrKnhtzf9ycE icC1cgR5rl5yZBKqcQ+TnMFfP4KyEycAUA+qE0Aiz15vzV+syOheda/lksULuTJ76lXv x6v2PjLOWaE1jimMRB0sgrhqGXbjOCWI5pH+8zVAnB/1dtanstPrGc8xm9u7/MPI51Ny 4wg0y1tX7oAoazeGN6Gmb9N5tTkpVmA8y03LeJNNdbveEGly63+bVJpbS5iqj3rr3MKf kjVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MfXzdbDQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r2-20020a63fc42000000b005651147ebfdsi7952873pgk.127.2023.08.14.04.47.15; Mon, 14 Aug 2023 04:47:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MfXzdbDQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232359AbjHNLTi (ORCPT + 99 others); Mon, 14 Aug 2023 07:19:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234628AbjHNLTQ (ORCPT ); Mon, 14 Aug 2023 07:19:16 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B91EE61; Mon, 14 Aug 2023 04:19:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692011955; x=1723547955; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=ZhSEjoUXC35XUl0gMa0VRDhMcqAcBMwzp6bvDUO45qQ=; b=MfXzdbDQhHQ9Ye5pbL5rhlIEH1uOK8q2eH5BN2pFNmfqUJJc51IYemVW eECFiHjzGM49czWpwTpjQ+NuCxvPWVUkDpPU1MaYhFn6R44eVQsRIdDfJ 2gjlUQ8YsYWr7eonxBWdEkd/dOgJ+CN238jzYUpI/moNHlNbCG+HfvXYm 5jn+ODTzyb4tFsdRIvihtqmfIKNwjv/C1BCCVB8ZbeguqpNHoMGbRP0gE 4KZs3i+PGwqVYHtC52Iy3z8Ap78qi1OWobsXB+0v94RRf6enpTo2XHOf/ IEn/EDxs69AV5vYu0oAY8/YysTGqsAdUxrErTndN63BvZ7zPjv9bFdCWK Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10801"; a="370913965" X-IronPort-AV: E=Sophos;i="6.01,172,1684825200"; d="scan'208";a="370913965" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Aug 2023 04:18:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10801"; a="857049356" X-IronPort-AV: E=Sophos;i="6.01,172,1684825200"; d="scan'208";a="857049356" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga004.jf.intel.com with ESMTP; 14 Aug 2023 04:18:57 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 38412374; Mon, 14 Aug 2023 14:26:17 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko , =?UTF-8?q?Marek=20Beh=C3=BAn?= Subject: [PATCH v1 1/1] gpiolib: sysfs: Do unexport GPIO when user asks for it Date: Mon, 14 Aug 2023 14:26:15 +0300 Message-Id: <20230814112615.42448-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE autolearn=ham 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 It seems that sysfs interface implicitly relied on the gpiod_free() to unexport the line. This is not good and prone to regressions. Fix it by explicitly calling gpiod_unexport(). Fixes: b0ce9ce408b6 ("gpiolib: Do not unexport GPIO on freeing") Reported-by: Marek BehĂșn Closes: https://lore.kernel.org/r/20230808102828.4a9eac09@dellmb Signed-off-by: Andy Shevchenko Tested-by: Marek BehĂșn --- drivers/gpio/gpiolib-sysfs.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 530dfd19d7b5..50503a4525eb 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -515,8 +515,9 @@ static ssize_t unexport_store(const struct class *class, * they may be undone on its behalf too. */ if (test_and_clear_bit(FLAG_SYSFS, &desc->flags)) { + gpiod_unexport(desc); + gpiod_free(desc); status = 0; - gpiod_free(desc); } done: if (status) @@ -781,8 +782,10 @@ void gpiochip_sysfs_unregister(struct gpio_device *gdev) mutex_unlock(&sysfs_lock); /* unregister gpiod class devices owned by sysfs */ - for_each_gpio_desc_with_flag(chip, desc, FLAG_SYSFS) + for_each_gpio_desc_with_flag(chip, desc, FLAG_SYSFS) { + gpiod_unexport(desc); gpiod_free(desc); + } } static int __init gpiolib_sysfs_init(void) -- 2.40.0.1.gaa8946217a0b