Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3091828rwb; Mon, 15 Aug 2022 17:55:49 -0700 (PDT) X-Google-Smtp-Source: AA6agR7psezsZ4Ge+fwlUY2qFYLwP4Eiu1dRF/Dx3QNHQILYYMYUfXNQyKlfFS0hNFYGZvCacYcI X-Received: by 2002:aa7:c983:0:b0:43d:3879:216b with SMTP id c3-20020aa7c983000000b0043d3879216bmr16559496edt.131.1660611349297; Mon, 15 Aug 2022 17:55:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660611349; cv=none; d=google.com; s=arc-20160816; b=hgFISpZl+WtTVYtR/JTloS43DJIuiKPLwBV8tfwcs0WDnYLlqu8g09q0Orl33Y7eBq qi8iIaWzal1Ox3d6VbY+rAV4Hx65sP/buMnxBUisK0SArRm+Za9CadAUbwftIwE47nxx A4F/6tCwHFPj4bpJO/nJBBMp946tGE6KhF9i4OYnRAmKTsqCV9ftsMYiOTq9G7EMleGE RotiXKGbWAIc/morttwzstplvX5krtdsNbcZG0H7iCB5slaITCzgn4tXZPUctv1Y4lIv 1UYDVstQmQBrg0BfyiYvF/J7fFo9xFB87XrTPKXt808JNqJBICv4BBeehuCLeimdn+tV 5tHQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5Vdd5eFq8DfxhBW9we7CllCJBTSeT/OAtbXtlk1EPTc=; b=GJgkzKGnsPR/7uzh5SpMQNpmS6i7WaBDCUFd4Qfty+ouVuCFKNwjnyBPDVaedaGrdu uYGoqqr1K51srVZNa4EYEFXQSpsc8POtk2vmWpZ9LQzbrzZpVbNP/xBVTBjC69/oXKNL dVUp4y7OHDV9xpphHP7XO/2WmLdGjSeVgf5I4Ucc4/Jrpz56tCX9Kinu2G45GAAam5nO H8SIIWrEkplvZXYCD+f8HctV/EaeOV55HBEHQ2UQL3mfTA6U3YwbnSCmweuNMOV4MT3s yemogoHEOFxSh11RXd4VldeLlKK6qrdIghunS67FER5acY/m8Hg06cVt5puuajbr2a19 /2yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="AufXQEy/"; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c7-20020a05640227c700b0043be28d93adsi9887024ede.261.2022.08.15.17.55.24; Mon, 15 Aug 2022 17:55:49 -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=@linuxfoundation.org header.s=korg header.b="AufXQEy/"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245365AbiHPAeS (ORCPT + 99 others); Mon, 15 Aug 2022 20:34:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353691AbiHPAb2 (ORCPT ); Mon, 15 Aug 2022 20:31:28 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6FC518599D; Mon, 15 Aug 2022 13:36:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 65CB0B8114A; Mon, 15 Aug 2022 20:36:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F21AC433C1; Mon, 15 Aug 2022 20:36:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660595763; bh=MCXpGzAljQyU9//it1iIzxOk/vrAdFjns2DFn7aJgXU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AufXQEy/FWDTiE5tL0AlsrrPyp7zeLrnDALIBJlxTqItkcj5uZBc+2wu5E2osNHnV pl7ZpYU/E1jVmVAVx4D5/6J53w/Eys3rsWAswlVFEkUiRKau7G682WP+ggQ3xdgpx3 2Qy6Bg2l0r0Xxxf8mgUJBC7krwr0OIh/a6qUX3NU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Liang He , Bartosz Golaszewski , Sasha Levin Subject: [PATCH 5.19 0834/1157] gpio: gpiolib-of: Fix refcount bugs in of_mm_gpiochip_add_data() Date: Mon, 15 Aug 2022 20:03:10 +0200 Message-Id: <20220815180512.846477387@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Liang He [ Upstream commit 5d07a692f9562f9c06e62cce369e9dd108173a0f ] We should use of_node_get() when a new reference of device_node is created. It is noted that the old reference stored in 'mm_gc->gc.of_node' should also be decreased. This patch is based on the fact that there is a call site in function 'qe_add_gpiochips()' of src file 'drivers\soc\fsl\qe\gpio.c'. In this function, of_mm_gpiochip_add_data() is contained in an iteration of for_each_compatible_node() which will automatically increase and decrease the refcount. So we need additional of_node_get() for the reference escape in of_mm_gpiochip_add_data(). Fixes: a19e3da5bc5f ("of/gpio: Kill of_gpio_chip and add members directly to gpio_chip") Signed-off-by: Liang He Signed-off-by: Bartosz Golaszewski Signed-off-by: Sasha Levin --- drivers/gpio/gpiolib-of.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 3d6c3ffd5576..de100b0217da 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -860,7 +860,8 @@ int of_mm_gpiochip_add_data(struct device_node *np, if (mm_gc->save_regs) mm_gc->save_regs(mm_gc); - mm_gc->gc.of_node = np; + of_node_put(mm_gc->gc.of_node); + mm_gc->gc.of_node = of_node_get(np); ret = gpiochip_add_data(gc, data); if (ret) @@ -868,6 +869,7 @@ int of_mm_gpiochip_add_data(struct device_node *np, return 0; err2: + of_node_put(np); iounmap(mm_gc->regs); err1: kfree(gc->label); -- 2.35.1