From patchwork Tue Dec 6 20:07:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 30487 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3026784wrr; Tue, 6 Dec 2022 12:08:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf7hgnqCmUCkxhBGVrf5JSpnJbWINp8l5JfdjfZOuC2rF1Vs1ZbJYt94rzihiMnJzqE5CUCd X-Received: by 2002:a17:902:d647:b0:189:cf7a:b564 with SMTP id y7-20020a170902d64700b00189cf7ab564mr13954507plh.8.1670357336370; Tue, 06 Dec 2022 12:08:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670357336; cv=none; d=google.com; s=arc-20160816; b=RMdQ2eovrJlOqJxEmt8LyaW0DqBG05FPSngkAdgCUO2HBJYop1hmPJ2/Vln4Dj5duO NkY8x/8GI/hzIvcVBNc5SC5O0WRpEe9X9JsmD+WEb1wvKXJ5nhvVCcvCDN13sZbKC3Uj SWcGaUn9b1MzEJChH9FriKXoVNYKRkFp5F20LqMO2/gZd9j/tvEm+tWPXBEjYn+xZwSg JzY4i7QGuKfS7lRntwcp3jB8nSu8KGn3lBQswxxN1d5oiJ3FMO9JRsgXn0i5BLwF2ju8 Heq5SMIg47j+pWJMqvzQ9H7fa5UUGM37dYnz4/GEotAPsP0jQB7HmMxXvQwPnq5DoURS S/vQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0p2I5HS7ONU/w4jyInXwMyvq84/GI3/niID7ktTA84g=; b=Js3dDbiUZQNTNTzeor+0NTBN9l32YkgbizxUoUeOrVIKuGxuDC2WUCc0uuzqLoirj6 mAJFX7990c5qrHGwZbZDKgldB5/DfD8q2Cj9SAneCthIXvqoqvSG/XqkjWRp0TChnV86 5gRXLY//nms+JC4BIP6tDn6e4FhPydFhT6EPVjVm9sAL+KtdCoWV5+IjMqITiIEP9aHa Q05HkkT129p7PXCQ53mKaqjfWqckJOvgW13f1sg0ULUAGNjkYa6SpNKpm2eJlK1qfNgk es3txGHly5V2yPRcxoWpDudx02XyYowIi8UK3P2eJVb0JWP6cF1e+qLqmtFhEYeK8ePy Y6jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=iPQL7UZp; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=walle.cc Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h11-20020a056a001a4b00b00547d55a4d3bsi18579580pfv.285.2022.12.06.12.08.43; Tue, 06 Dec 2022 12:08:56 -0800 (PST) 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=@walle.cc header.s=mail2022082101 header.b=iPQL7UZp; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=walle.cc Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229564AbiLFUIU (ORCPT + 99 others); Tue, 6 Dec 2022 15:08:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229715AbiLFUHz (ORCPT ); Tue, 6 Dec 2022 15:07:55 -0500 Received: from mail.3ffe.de (0001.3ffe.de [159.69.201.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA9B3D2EA; Tue, 6 Dec 2022 12:07:51 -0800 (PST) Received: from mwalle01.kontron.local. (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.3ffe.de (Postfix) with ESMTPSA id A50803B28; Tue, 6 Dec 2022 21:07:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1670357268; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0p2I5HS7ONU/w4jyInXwMyvq84/GI3/niID7ktTA84g=; b=iPQL7UZpEggmdZC21h8CNYAchb00M7jJP9hFmVO68NH1Aoq6L1DqOPUiUESa3QCM3RxOmS hFlxcjpPHoFyaDpHFiN+wNAOfsTegJ8zaQQFhyOB9GvgXodaEiX45QKf2YE6LN07P/5R7W PABgorR2RdBI9AehiU27bTuCKQvjUjddyoR2sRW0fimRHFOb4lqvg6PQ+UI5XtIDuHhV9t +ai38+f2GCPQfZfL0CDZLWJ6pBGy3PnSon/6XCBZGKDv9q9JaMxIaJSfnZnTqDTH5F+nOt c+VkbXs/fuWNayROQUe+T0OWzhqlOW0+Gi2BKvt8DRCH3WpqXoVbvO3HA5rzZQ== From: Michael Walle To: Jonathan Corbet , Srinivas Kandagatla , Miquel Raynal , Rob Herring , Frank Rowand , Sascha Hauer Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, Michael Walle , Dan Carpenter Subject: [PATCH v5 05/21] nvmem: core: fix device node refcounting Date: Tue, 6 Dec 2022 21:07:24 +0100 Message-Id: <20221206200740.3567551-6-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221206200740.3567551-1-michael@walle.cc> References: <20221206200740.3567551-1-michael@walle.cc> MIME-Version: 1.0 X-Spam: Yes X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751496614223521044?= X-GMAIL-MSGID: =?utf-8?q?1751496614223521044?= In of_nvmem_cell_get(), of_get_next_parent() is used on cell_np. This will decrement the refcount on cell_np, but cell_np is still used later in the code. Use of_get_parent() instead and of_node_put() in the appropriate places. Signed-off-by: Michael Walle --- changes since v4: - none changes since v3: - none changes since v2: - new patch drivers/nvmem/core.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 321d7d63e068..205a427f564d 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -1242,16 +1242,21 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id) if (!cell_np) return ERR_PTR(-ENOENT); - nvmem_np = of_get_next_parent(cell_np); - if (!nvmem_np) + nvmem_np = of_get_parent(cell_np); + if (!nvmem_np) { + of_node_put(cell_np); return ERR_PTR(-EINVAL); + } nvmem = __nvmem_device_get(nvmem_np, device_match_of_node); of_node_put(nvmem_np); - if (IS_ERR(nvmem)) + if (IS_ERR(nvmem)) { + of_node_put(cell_np); return ERR_CAST(nvmem); + } cell_entry = nvmem_find_cell_entry_by_node(nvmem, cell_np); + of_node_put(cell_np); if (!cell_entry) { __nvmem_device_put(nvmem); return ERR_PTR(-ENOENT);