Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp912096rdb; Fri, 1 Dec 2023 01:46:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IHRns75aQNjgKUDrjhAj+oErmz+mufvs5gBlyezY3p4M+yRyWp5LGA0cC+c5Iw6jIzuYc0w X-Received: by 2002:a17:903:25c7:b0:1d0:58d8:bb3f with SMTP id jc7-20020a17090325c700b001d058d8bb3fmr699586plb.49.1701423971663; Fri, 01 Dec 2023 01:46:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701423971; cv=none; d=google.com; s=arc-20160816; b=VQLQ7QHRNHx2bw9uUnHvpLj8lEKpwKoTSlYnXT+o5kJ7r8K6dgFDc+czZe+UrSRApZ 2vDqag3ZE6u063u0z0/KDH4+Ig2I7IIjytEPcdf9GV47RcaQbjE0TO+kpbjtqmv81rmN c2Pn4og7G5L5nojZhO8+xsnJ7TJhQq+qvcG+K9ac58WFvHknC940QncUQVidOMiKq2Bp sxrQS49VUw4V/j7Zh7kWrcINvjWTAY5tVa/bNwZpohKlkyDNx3VGSs9nxSJDd2T9a14L m6LyNkrZ8Z+dpdmRLw7V/EifbbQ0eQoRheM+lGOdU7kdeTyIdQb17rcwo5ZwTLdQ5iAc UT8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=9ekfjW5/RgeJMklE7juR1PMpyxSeXgb7TqD/ojEgNQc=; fh=nQboLGmPyrYVYKNohsdvOoS0mAdoHu+gNq8zeoAi5MY=; b=sLmQFv9xV6e+4fAS4AjrSE9I4eSlNQpO2tGB8sCU7m9a8xiAtLQ3bB+rtfuEufFGs/ QOliZoKT/HJ/fBs3mg5DNuqeprrobC+MrhcA5/nJs/oJF2tpuEaLq8LdyQrr11MsI/aQ A1CNoQcP/1zanCG2fa9o8jGz7P2SZ4eDtE1ojzkCoz+0ySXYdZUKHWe/Wo96OA4uDUjQ AbtuIse269vlFqfp1AYF7fgOT4hiCfkSX8Fpi66eosVAvMvNHqvXDc6jWY6xm42ynKg0 cRzVFwh7cypSGcez52/mh6pdr8/AjtenBllufxZTVn017bFFbyAyg0JSGle0m5HMIYEW 7gjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=RiGjBsq5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id h13-20020a170902f54d00b001cfcd4d8f2fsi3175419plf.351.2023.12.01.01.46.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 01:46:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=RiGjBsq5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 9B0EF8097796; Fri, 1 Dec 2023 01:46:01 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378044AbjLAJpp (ORCPT + 99 others); Fri, 1 Dec 2023 04:45:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378047AbjLAJpj (ORCPT ); Fri, 1 Dec 2023 04:45:39 -0500 Received: from mail-vs1-xe2f.google.com (mail-vs1-xe2f.google.com [IPv6:2607:f8b0:4864:20::e2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76CC010F3 for ; Fri, 1 Dec 2023 01:45:45 -0800 (PST) Received: by mail-vs1-xe2f.google.com with SMTP id ada2fe7eead31-4645a9ab3d2so534484137.0 for ; Fri, 01 Dec 2023 01:45:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1701423944; x=1702028744; 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=9ekfjW5/RgeJMklE7juR1PMpyxSeXgb7TqD/ojEgNQc=; b=RiGjBsq508f4Xnodj8k5T9pILSjQRsHEhMzLYt37HgBTQtRbfowOIOb9wfbMgzVXCd 0/NdgOaZeeGhkSbomoGCl3c+918KoFMrdJCg8xRcpZTbfu1TygZSMUbxTHwtug34Kfzd I65Xjnp9YQo5CGIDwqRNDs3C9o1wMzujGSn2ORkL3ulKAnDh6gLbE7/L1ydp7RJdisso yCGdTBOfdJHykysDnP6dQiFHLecWAK0eS/PHcIsPAb9/Ge80jIhb8OwdmG4iIQpEeGKa SWdISdHaHgR0nGtxE0dkPpCiPKT3p9frsfaIsyYFhx1VCArOLbCKqq90s4kFBcOwZiup z9VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701423944; x=1702028744; 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=9ekfjW5/RgeJMklE7juR1PMpyxSeXgb7TqD/ojEgNQc=; b=DDZ/sa888d4vt73Sv6qoTwf3kOeG7RoPYuBxvrUpnGXyw4QWd4dmFN2sx28n5GGN2k kfCLrYX1UfaqRp60oxrpuPdoFZrwJGD/4l2ziuGyl+lTDJ7sXhLANQFHCX7a8UrJB9Ho uDC1eZKQ+45tvJuhTnDX8UmytAvChioy/oJtP+AeNqm/t4PlnwMcKrsTlhy1u3jd2z6p CdyNFCb7XPKm0ZpFHVqvnb3TrA+eutYH+p3cLduZiwxpC97aXLVLrYQ3bdv5qu3svgcb k3WKeK5mRmVhMK+lVBoMHiZdMeOux11JFVVqaMh6Jf7BDbFb9S7ENy/rdumQOn/l7XKZ HODw== X-Gm-Message-State: AOJu0Yzv8Xb88569jGGZ6qz6AJBzT5Okpg4a8ET474KZCfyEv8QrJBsZ UL5dkG9N0t4dpLL0LIAPFT5MR9FxadhwapIERsqP6w== X-Received: by 2002:a05:6102:450:b0:464:6018:abc5 with SMTP id e16-20020a056102045000b004646018abc5mr3747554vsq.5.1701423944545; Fri, 01 Dec 2023 01:45:44 -0800 (PST) MIME-Version: 1.0 References: <20231129152307.28517-1-boerge.struempfel@gmail.com> In-Reply-To: <20231129152307.28517-1-boerge.struempfel@gmail.com> From: Bartosz Golaszewski Date: Fri, 1 Dec 2023 10:45:33 +0100 Message-ID: Subject: Re: [PATCH v3] gpiolib: sysfs: Fix error handling on failed export To: Boerge Struempfel Cc: andy@kernel.org, Linus Walleij , Andrew Jeffery , Charles Keepax , Rob Herring , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, bstruempfel@ultratronik.de Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 howler.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 (howler.vger.email [0.0.0.0]); Fri, 01 Dec 2023 01:46:01 -0800 (PST) On Wed, Nov 29, 2023 at 4:23=E2=80=AFPM Boerge Struempfel wrote: > > 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. > > To my knowledge, this does not affect any current users, since the > gpio_set_transitory() mainly returns 0 and -ENOTSUPP, which is converted > to 0. However the gpio_set_transitory() function calles the .set_config() > function of the corresponding GPIO chip and there are some GPIO drivers i= n > which some (unlikely) branches return other values like -EPROBE_DEFER, > and -EINVAL. In these cases, the above mentioned FLAG_REQUESTED would not > be reset, which results in the pin being blocked until the next reboot. > > Fixes: e10f72bf4b3e ("gpio: gpiolib: Generalise state persistence beyond = sleep") > Signed-off-by: Boerge Struempfel > > --- > > V2: https://lore.kernel.org/linux-gpio/CAEktqcv8NC0Cy+wo7nRGOp9USoBdta=3D= n=3Dmrbo-WomxgcmWN5nQ@mail.gmail.com/T/#t > V1: https://lore.kernel.org/linux-gpio/CAEktqcuxS1sPfkGVCgSy1ki8fmUDmuUsH= rdAT+zFKy5vGSoKPw@mail.gmail.com/T/#t > > Changes from V2: > - Capitalized all occurances of GPIO in commit message > - Added Missing - in front of Error Code in commit message > - Added Fixes Tag in commit message > > Changes from V1: > - Marked all functions in commit message with parenthesis > - Elaborated in commit message > > 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 *cla= ss, > goto done; > > status =3D gpiod_set_transitory(desc, false); > - if (!status) { > - status =3D 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 =3D 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 > Applied, thanks! Bart