Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1861242rwb; Fri, 19 Aug 2022 10:36:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR42vCdk1hXhu/6VkM3WyJ/WYz5jDlQm+9UxQ72AfZk1FG5pprMkPTgB1EmCAe+4Ik3Mu43/ X-Received: by 2002:a17:902:c941:b0:16e:fe88:99e5 with SMTP id i1-20020a170902c94100b0016efe8899e5mr8488709pla.38.1660930563660; Fri, 19 Aug 2022 10:36:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660930563; cv=none; d=google.com; s=arc-20160816; b=wFdI58iECJl444OIjjYUX7+7DtLnBHQX+sPdcijDbueAJ5aZXAnS73HjHx1IAWeBIg sOQZlpizduUVddra9t9y7GsUD4FKSsZ8CuSnNtClX/NUlzYk4UP/Ov9PutAbrfhy2+w9 P4XpbME3JfZc8PRzEGs39H+mSKHdIj0Kj79ajk6SqT3Izt1ukoXk+UDNh2Eo/4j1FGIq 4abh2iRd8Ka/QwgbD8g7UXuZRDkR5evVvacjqe5QK+EP1U0PWFWxR0f35ePtXJKAa9wp h9eoe5X0Yj+TEDbG3r4VX8ab6JGjMJTzUGgbE8HNBveNE9KyQ9gu8Tn8hXwAeFuWuVfT K1yw== 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=qFYgFvsoH0NsnyIuS+0vUDDxo51/D2wO8bBy9+DSU+A=; b=rmouCK6kLfCCgsRVqXd70+dA2K0eQdX3LYa9FS1XJB4/E7G3IYKVbVJE1Hb9POjdLc og55zkyrbzQsINjhhbn8ctQaIR1wPJvU7HYj1dHbpSdiq9UJ13g7g2ZLK9xvIjBsZ0Gs JyeHwmtFomBRcVCvhui5TsUgwVwaQy1uJkgg6T1mFGn8rPx9w0/hhlikF0P/tkIkG1hD MiH8+OmNNLfNkNStVjrblWK8KKCZKtuRYhbFEOAwXFbbxuIepXrkdPN0GlovzA562ulA pnxG+12u6fYn6U1lvwRCk+IQV0I7n7L2sEz9mh04NWSqgWAFg8WMfSXu+pvez45ubO80 mo8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mFsLonYc; 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 k9-20020a056a00134900b0052e525cc159si5234756pfu.160.2022.08.19.10.35.52; Fri, 19 Aug 2022 10:36:03 -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=mFsLonYc; 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 S1352702AbiHSQ1A (ORCPT + 99 others); Fri, 19 Aug 2022 12:27:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352326AbiHSQWC (ORCPT ); Fri, 19 Aug 2022 12:22:02 -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 45DCED4774; Fri, 19 Aug 2022 09:02:54 -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 03469B8280D; Fri, 19 Aug 2022 16:02:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62715C433C1; Fri, 19 Aug 2022 16:02:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660924971; bh=8bpU67eqb8WPMzD9hcA8NYNJGxS6i9S0T8KAvq3ofH0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mFsLonYcCnxSf0K+qqhy951hK38JjFZs2l/bQUQ0/di4zMjuwMUelrclpiZ19DKqa E0kg7hrg7rkSWIdu5eyTX7DRbUEUgOYX8MaoJkJuU+ZyrPCpOuHycu4dAMUC7jbsqy ok389wZBhpxlwXa2VbnHYez+xgTUS3Vbfc8eth1Q= 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.10 340/545] gpio: gpiolib-of: Fix refcount bugs in of_mm_gpiochip_add_data() Date: Fri, 19 Aug 2022 17:41:50 +0200 Message-Id: <20220819153844.610960518@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153829.135562864@linuxfoundation.org> References: <20220819153829.135562864@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 01424af654db..2e63274a4c2c 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -863,7 +863,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) @@ -871,6 +872,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