Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3416512rwa; Tue, 23 Aug 2022 04:32:38 -0700 (PDT) X-Google-Smtp-Source: AA6agR4tx9/iZrnEhVMVC8iBwWt52vp00Aqw4ce8dtaYcSLabHNzTdc6PzouIpwBw1Fdr6oU5LQN X-Received: by 2002:a17:906:4787:b0:734:1ad4:aff0 with SMTP id cw7-20020a170906478700b007341ad4aff0mr15598222ejc.317.1661254235637; Tue, 23 Aug 2022 04:30:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661254235; cv=none; d=google.com; s=arc-20160816; b=IpPKAc2+helPvRwqsHQ0CPDB9SVIKp9QOXRvineLLH8aree3KKU+dzxvGOhrYDQ0hi OzjhdQH60HHYysprRvif+E3zqpcM5nalyfKWqZ3m9TEDV/zM2OlhNH7aUgo8Pthfey7x Qhp4ljnhsgtIBfPgE02eQSoyPBmlELOGa6+OW7Gb9Qh+9ByWwssOMvDk5qNzcaNzLkWj 492uE+koykXsgCcn0d/tKpA3Z1/qnAINQ0yD/qTQAshCvHYpJh8HVYdErNNYjUdwz3xv 8YzvakN3HWi4KGXgz7hW/jGZsvcFzchKi3cbrd8QvTOG5eZymP8Lb+fJuIu7Zg1pxzUc 4Ulw== 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=F+KhETqY2SBfpRcbeXw1xu642QhIrjX8e/Ok06McyLY=; b=bNowxco7Z9sM0MKuhMT0CzHMpMypBs0vg5QKRxICfVxqCmK2y5jTKtxl253dHBIvfC lGrMROR8/9jqeyjdm+Y/3hdBcNWK1AP74GV+oS1ypnkYfia8luFBcQ+ypJIoT4QdCD3w isi3mLKDx8cyOHILcYYiuwgo8ttApy4NBP+tnH9xDWakvrAECawXfbYffgOJ0OCR239O VyGBNpTThuJZjH3krTiLlSWeUMHf8/iIvhbHmnDD+BY0pWpSTJJtHPyWU7njd/I/LmwN BmsuCcBXgryrw8HqpoXEBfsylMuq4ZjwZwxJbdDiw5Mw1+2eHljIioh2PrEnapUdDMPv iUTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=U1eb8yFU; 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 b9-20020a056402278900b0043e74bbfab2si2293813ede.162.2022.08.23.04.30.08; Tue, 23 Aug 2022 04:30:35 -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=U1eb8yFU; 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 S1355698AbiHWKoE (ORCPT + 99 others); Tue, 23 Aug 2022 06:44:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353625AbiHWKe7 (ORCPT ); Tue, 23 Aug 2022 06:34:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E841A61D0; Tue, 23 Aug 2022 02:07: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 dfw.source.kernel.org (Postfix) with ESMTPS id 45F4F6156F; Tue, 23 Aug 2022 09:07:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C834C433C1; Tue, 23 Aug 2022 09:07:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245622; bh=em6fE2WEIEaDG8U9cC/Dtp6StwJew9mwOQxtaNxLcHY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U1eb8yFUe0b5kqPVx+ZhZ+eOWoktIibrXb1nVFcVYSgwiNuRstyxu9+Tvz8FccDnh xG85PGdsvWoJa3SdbQkR85+TRJL3ykbUS4ed5lQJOXedJT33rQg+yZ1Zbf4UvEcfmK +WMDCbPCXg2FNzkwZXXLVuHTKOAwIQecPD7uZMmM= 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 4.19 135/287] gpio: gpiolib-of: Fix refcount bugs in of_mm_gpiochip_add_data() Date: Tue, 23 Aug 2022 10:25:04 +0200 Message-Id: <20220823080104.989173101@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080100.268827165@linuxfoundation.org> References: <20220823080100.268827165@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 09999e3e3109..7bda0f59c109 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -476,7 +476,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) @@ -484,6 +485,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