Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp337272rdh; Thu, 23 Nov 2023 05:30:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IF3HakvLTMZ1iPzfJwpx0qCJZ1VrfuLPrvCL3LAMLN0LW0f6wkO/ic7nBzoEYCAd34qo+zA X-Received: by 2002:a05:6a21:1c89:b0:187:e3a5:b35a with SMTP id sf9-20020a056a211c8900b00187e3a5b35amr4777744pzb.21.1700746230792; Thu, 23 Nov 2023 05:30:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700746230; cv=none; d=google.com; s=arc-20160816; b=DQcdkCU0bKhxbcWjpCSQk4Hkh3TYiEm0ppUiTOSKmy5P08z/z4pSLfkopbo204RHnQ ayIiQAz0KQinaOHu24ec8ooITBhP50+9J/08xNyNIvq1hph6DGXnKovfXn5LPPGhBKCX MDbUicFHHTLByeMbt2HijJf78kDpKdsAHa2DVX14ptNWEg9/9eIo+Vj3AaZ5ZJ1T3q62 2o1bANRxJFdq1+KoOYUYMt7xRNjlOlzcvYPNnIT3yWXmivEj9mNzDaVBDoAuf1m/csqn eOM3vVdOAKXAyGJzteEomI6pun8xGAeXJmzMi1L4K2lE+7QNUB+joM2ZsnY7R1EA+Mvh LxQg== 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=RC4QAeE+mvvSH3pdAbHu8q/LCZTxCmKiOR39w4ENfFU=; fh=+Ipn30RPmLnTh9hCvDwZ8g8QEXTsR0cn2KRfguVqbG0=; b=k18O2tzCELEpQmQ2zaF6bhlOx1BAirAEP2YhEZhxGgN6gS7vfgV7F37CqxLL7KJJfe wnRttBfZ3OKXuztko7v9YirR32IViEZuhW67E78tQF5p8FDiWmWiuhAdkL0ptSEi1DNk rsE5Aoit81N6MKPcAXq0YAKam1V3Ja1/OUVpSF/CwDIcTWIwwCwmv3EJKiKoW54BJO2K m3UR4yryl3CKrB8DPtqOtld51ZDtSa4M6cL18IhiZ/w5Y438yoEUTo9Gxh0p94AgmPdY YLTpogF8Ejqah+ZzCiTeW/7K0WD74yopWb/qLk5melW0RSRNbvlCmjZNe17tvU519hnH EGtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Jeq3G588; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id bg3-20020a056a02010300b0059b79bf220csi1301400pgb.662.2023.11.23.05.30.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 05:30:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Jeq3G588; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 60F6D8082703; Thu, 23 Nov 2023 05:30:28 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345467AbjKWN37 (ORCPT + 99 others); Thu, 23 Nov 2023 08:29:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345271AbjKWN36 (ORCPT ); Thu, 23 Nov 2023 08:29:58 -0500 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 061E61A8; Thu, 23 Nov 2023 05:30:05 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-548f853fc9eso1221525a12.1; Thu, 23 Nov 2023 05:30:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700746203; x=1701351003; 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=RC4QAeE+mvvSH3pdAbHu8q/LCZTxCmKiOR39w4ENfFU=; b=Jeq3G588GFcYOZUyT2cFVEXBdcK/+86TpcYoACqoLVV7zBLNd5/Y5/8nGrasO1Jiib uEApfVPOiFZBEVSOLySRU8l+gKrFooIKNTDJ1JG7l+e21Ms5p9FXIttHspVWWx0kQr2m NLoM3TnlmYSMOsHDCF6Nh8jTVGdnWfEZPPt7tnaFuurNWtrmdQWuU6pxGXgoi9exiih7 dO2JJ9+sUu+bQbBCjKt/bPlqvqIxVgrgwO4fK0UIed006jPX23+jy0QukGY7Qdpd75SD ILI5zreONpl/USow9p1ywfIQ9TBAt1IyFuHeJIxOM0oaKB0VSfi6wepQGxlaWbbQsgUU ZCcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700746203; x=1701351003; 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=RC4QAeE+mvvSH3pdAbHu8q/LCZTxCmKiOR39w4ENfFU=; b=a4zWtaMG2uUQXYg1Bf8FCCODWvhPG43iJRdueHI8Tu1+p6DJ7mnW9kXLFz8kQ6GzaJ NyOZx4EA5DW9299akHGn4T+lAy+a5cA7gRogwkoGShsw46D3wuhwCYq9j+LIdPicMnkX 1MRn7ySN0pCDYOAnw3Dqu9B3iWWGr1A0kRq8398hwzFzSDLTmm5jJ92d+Zud4iM7Eyy1 QsBUswyFJZWP3h3ilELBQFtg7MUl0ZNyTsG1VgaXXuBbjv53lHBvrihq0V8xS16yaVy2 E7/eCiMhjP/JqTSUMpuqJpgq2m0rzSKeJAdXLUiDuXitdQDfF9Icp+ad50SADEKnqKad w3NA== X-Gm-Message-State: AOJu0YyWFJoPZqF29nJdID76JDM58dIxIRyXboq9zRbNDc3kOcJPL7FG vbhRO/sQbR/WG237G1F/JLI= X-Received: by 2002:aa7:ca54:0:b0:53e:8972:1d4f with SMTP id j20-20020aa7ca54000000b0053e89721d4fmr4641212edt.5.1700746203205; Thu, 23 Nov 2023 05:30:03 -0800 (PST) Received: from wslxew193.ultratronik.de (p200300c7874fc8005124cc901e9d78a6.dip0.t-ipconnect.de. [2003:c7:874f:c800:5124:cc90:1e9d:78a6]) by smtp.gmail.com with ESMTPSA id d17-20020aa7d691000000b005434095b179sm654281edr.92.2023.11.23.05.30.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 05:30:02 -0800 (PST) From: Boerge Struempfel To: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: boerge.struempfel@gmail.com, bstruempfel@ultratronik.de Subject: [PATCH] gpiolib: sysfs: Fix improper error handling on failed export Date: Thu, 23 Nov 2023 14:27:49 +0100 Message-ID: <20231123132749.108827-1-boerge.struempfel@gmail.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 pete.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 (pete.vger.email [0.0.0.0]); Thu, 23 Nov 2023 05:30:28 -0800 (PST) If gpio_set_transitory fails, we should free the gpio again. Most notably, the flag FLAG_REQUESTED has previously been set in gpiod_request_commit, and should be reset on failure. Signed-off-by: Boerge Struempfel --- drivers/gpio/gpiolib-sysfs.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 6f309a3b2d9a..12d853845bb8 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -474,14 +474,17 @@ static ssize_t export_store(const struct class *class, goto done; status = gpiod_set_transitory(desc, false); - if (!status) { - status = gpiod_export(desc, true); - if (status < 0) - gpiod_free(desc); - else - set_bit(FLAG_SYSFS, &desc->flags); + if (status) { + gpiod_free(desc); + goto done; } + status = gpiod_export(desc, true); + if (status < 0) + gpiod_free(desc); + else + set_bit(FLAG_SYSFS, &desc->flags); + done: if (status) pr_debug("%s: status %d\n", __func__, status); -- 2.42.0