Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp1217909rdg; Fri, 11 Aug 2023 13:52:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFsZ6zicuBgxa1Tj3/BOiva+sh3T/EP5Zrluw3Nz6o7xGxulhGTNmHpsGZ7lcoxnTT2J1tG X-Received: by 2002:aa7:d390:0:b0:522:ca7c:df78 with SMTP id x16-20020aa7d390000000b00522ca7cdf78mr2469934edq.0.1691787154004; Fri, 11 Aug 2023 13:52:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691787153; cv=none; d=google.com; s=arc-20160816; b=ZSyObIuYEt1WHyTpLl9jYu5+/R9Szi8HuWhXBrKFVU6Ym4nEWOrSPEDWb1s3dcmcD1 UyrDD/ma29jw5UcWTl6I90ATGiIdWuZm6jHu3TIQ4VaTELyd4P8ip4+0V6JdIIqrHiKz wIDN92MR3ZdIXMuHjcg1K3wF9cJ+ruvx2T+1hBFpjXWbBMMYH1wf45B8EpKNdvvjSJ7m VEEbWn4eCwpAyMxpFII+JJlxf1fV52r9OsHRz7gFcrqZEMgOzfLyIQPMKi8Zd6uU1YQ/ brhkJBu1gUnMj/ONhN5lau6cptdGxNKD6pWWuz9cGIw8VuBXdlqB4HjBxZdERGi7dhdf WBIA== 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=BpvKbuECMPzdBo5ZNQCPGKS5T7oO9/mxI/5xeP2hJcg=; fh=rCqKS5Wgxyvu9nhWEkn7CU+OTiPpAXAWtEe1ogm7zOc=; b=SFqeCOQ4UaMLRIOyT3j1NYYEDrO5Bv0Rsrc9tsMAArdp6QZ7He6WnFcJQ5cuFBKihd LvS/avmougIb+PQQ1nxyAu/UdmG0msv0x7i7KxrL0WDiG82zbG7bsWmBavxPJhYmVDPe gUjbB3WRrALP/28Xi538er1OpTgLeItCRLd6iLIUy6HA2zYr6msJMyTSRN11nxsK8+j5 6tldQke8tR4x+OsMRmfmSKAJmHCMZJonvhWI9EI9Hn3hb6+S6rn5gp5jvypvvwIocU6U kde9D90AhYEKw6zx/ZFD1s/DH4jbDZy5hWRoxWGTHZxRsptTcXEV6UC/R/AJ0kfgz6op zgKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20221208.gappssmtp.com header.s=20221208 header.b=aqV1Tqn2; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l13-20020a056402124d00b005234a88797asi4235262edw.648.2023.08.11.13.52.10; Fri, 11 Aug 2023 13:52:33 -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=@bgdev-pl.20221208.gappssmtp.com header.s=20221208 header.b=aqV1Tqn2; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236717AbjHKT1e (ORCPT + 99 others); Fri, 11 Aug 2023 15:27:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236714AbjHKT1d (ORCPT ); Fri, 11 Aug 2023 15:27:33 -0400 Received: from mail-vs1-xe2e.google.com (mail-vs1-xe2e.google.com [IPv6:2607:f8b0:4864:20::e2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1438D30F6 for ; Fri, 11 Aug 2023 12:27:32 -0700 (PDT) Received: by mail-vs1-xe2e.google.com with SMTP id ada2fe7eead31-4475d891d0eso1484693137.0 for ; Fri, 11 Aug 2023 12:27:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20221208.gappssmtp.com; s=20221208; t=1691782051; x=1692386851; 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=BpvKbuECMPzdBo5ZNQCPGKS5T7oO9/mxI/5xeP2hJcg=; b=aqV1Tqn26tAyC/1KKHSypfx8XCO2SbIK5Xs9IuOrpTXiiG2oVcgppsXhsuW5tvY/yO AgqGawkabEsouqMj8ucp4Q21Zvs0SRFa0jQaczetNt9yRyM0abJ0Yru88YN9yPaIZFuC hc2xSV+NenPYTMWviB40tPmc40wfmRWDT3NAozQ4THJXyMG07VPcmIa1Fbh4kOymNBBX lQh5aHANz29gZUTm3HZFeSaFGGdF1VSw7Bc8jdAhf2f+fomlQDblCtJe5MgicAVHZ3vS pVqmUkOiVJAZlv43oIxkKDuZ28MnHwLgTuYps+2VZfXieLVWbXVkI/ZffMz8ZUDF0mzi O8mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691782051; x=1692386851; 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=BpvKbuECMPzdBo5ZNQCPGKS5T7oO9/mxI/5xeP2hJcg=; b=anmAYtciD52ZlFAiN66RhevwWPF2pul+nEjVOgbqc4grUVcEooYy6Q35uBGdc0cKkI CkKeol3j2NyhLQ7KcGAg3OrF3TolBZpTYF1fA6mooG8dyb5cXwp/iy8L3nK94yAuYufS 103dS3QIy3Z07DuriS98IYFv7UMGi2+hwMwst7lXrRBcV5iJYSWfUSjAqfqmExunBIo9 5Wh2w8H5MdAdsKdtiHfycC83uPfMayy/kSCaTTXNxkiNTpFxyjyuAOBGOJoVpVWpAS4Z G+P8EwaFrZqufDw6gYRUaM3K51pHE2VyBfG1YcoBniyWoUVJT1+ccCESDCDSoy7dJ6rb F0iQ== X-Gm-Message-State: AOJu0Yws2OcZhPGLsiMNtZNUemMouh0s4g9zsyncPOsAzy9ObdkAKcmT TsLo3ROez74RrmjICkh2AaMZpzJ6EwmFxuPk47yowQ== X-Received: by 2002:a67:f996:0:b0:443:61f7:3ce with SMTP id b22-20020a67f996000000b0044361f703cemr2143192vsq.15.1691782051166; Fri, 11 Aug 2023 12:27:31 -0700 (PDT) MIME-Version: 1.0 References: <20230810184846.22144-1-brgl@bgdev.pl> In-Reply-To: From: Bartosz Golaszewski Date: Fri, 11 Aug 2023 21:27:20 +0200 Message-ID: Subject: Re: [PATCH v2] gpiolib: fix reference leaks when removing GPIO chips still in use To: Linus Walleij , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 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 On Fri, Aug 11, 2023 at 1:57=E2=80=AFPM Bartosz Golaszewski = wrote: > > On Thu, Aug 10, 2023 at 8:48=E2=80=AFPM Bartosz Golaszewski wrote: > > > > From: Bartosz Golaszewski > > > > After we remove a GPIO chip that still has some requested descriptors, > > gpiod_free_commit() will fail and we will never put the references to t= he > > GPIO device and the owning module in gpiod_free(). > > > > Rework this function to: > > - not warn on desc =3D=3D NULL as this is a use-case on which most free > > functions silently return > > - put the references to desc->gdev and desc->gdev->owner unconditionall= y > > so that the release callback actually gets called when the remaining > > references are dropped by external GPIO users > > > > Signed-off-by: Bartosz Golaszewski > > --- > > v1 -> v2: > > - add a comment about why we can't use VALIDATE_DESC_VOID() > > > > drivers/gpio/gpiolib.c | 16 +++++++++++----- > > 1 file changed, 11 insertions(+), 5 deletions(-) > > > > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c > > index 251c875b5c34..2158067c4fd2 100644 > > --- a/drivers/gpio/gpiolib.c > > +++ b/drivers/gpio/gpiolib.c > > @@ -2167,12 +2167,18 @@ static bool gpiod_free_commit(struct gpio_desc = *desc) > > > > void gpiod_free(struct gpio_desc *desc) > > { > > - if (desc && desc->gdev && gpiod_free_commit(desc)) { > > - module_put(desc->gdev->owner); > > - gpio_device_put(desc->gdev); > > - } else { > > + /* > > + * We must not use VALIDATE_DESC_VOID() as the underlying gdev-= >chip > > + * may already be NULL but we still want to put the references. > > + */ > > + if (!desc) > > + return; > > + > > + if (!gpiod_free_commit(desc)) > > WARN_ON(extra_checks); > > - } > > + > > + gpio_device_put(desc->gdev); > > + module_put(desc->gdev->owner); > > } > > > > /** > > -- > > 2.39.2 > > > > Queued for fixes. > > Bartosz Eek, I need to back it out. I realized there's an issue with this patch. I'll send a v3. Bartosz