From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B38FDC43612 for ; Fri, 11 Jan 2019 15:01:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 84C9C2133F for ; Fri, 11 Jan 2019 15:01:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547218881; bh=2pInYho9seUkU8kclyEpDIgr5/F1Zm9bsxr6Eu9EIcw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=buhnine8Bxc0ha1TECAR3nEPV9lVoLqqFHfL+9E68FBD8DAiVtYG3eTPAirjtmkCn 98jzzxXhUkK9RDLNg12ydYj+Y+FEEQceHaLwGx6xQWU7nAIomSk/zNTG7fKXRi7fZT +Q7ZScWAY5S8zN2BwWO77Cf+Cy2WWb9cWIvUyKXE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389383AbfAKOcT (ORCPT ); Fri, 11 Jan 2019 09:32:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:52202 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389325AbfAKOcQ (ORCPT ); Fri, 11 Jan 2019 09:32:16 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8354D2063F; Fri, 11 Jan 2019 14:32:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547217136; bh=2pInYho9seUkU8kclyEpDIgr5/F1Zm9bsxr6Eu9EIcw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZGLTmjt0S0JyMSQjimNgc8vUruozYbUNqwj2RbUpU6cxaLOlq2zFsKGZ0JZ2x/JiS PjDmSnLp5uzn0GSE0JnDkUwhjdWML/YsYyznfaXHeRV7+jj8pyzVG4appg9OzNSy7r qN8nihtJU1hiUKAB7neyvp6asstxxGjVTdbAzM4o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yangtao Li , "David S. Miller" , Sasha Levin Subject: [PATCH 4.14 054/105] serial/sunsu: fix refcount leak Date: Fri, 11 Jan 2019 15:14:25 +0100 Message-Id: <20190111131107.557819873@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190111131102.899065735@linuxfoundation.org> References: <20190111131102.899065735@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit d430aff8cd0c57502d873909c184e3b5753f8b88 ] The function of_find_node_by_path() acquires a reference to the node returned by it and that reference needs to be dropped by its caller. su_get_type() doesn't do that. The match node are used as an identifier to compare against the current node, so we can directly drop the refcount after getting the node from the path as it is not used as pointer. Fix this by use a single variable and drop the refcount right after of_find_node_by_path(). Signed-off-by: Yangtao Li Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/tty/serial/sunsu.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/drivers/tty/serial/sunsu.c b/drivers/tty/serial/sunsu.c index 95d34d7565c9..1cf78cec7461 100644 --- a/drivers/tty/serial/sunsu.c +++ b/drivers/tty/serial/sunsu.c @@ -1393,22 +1393,43 @@ static inline struct console *SUNSU_CONSOLE(void) static enum su_type su_get_type(struct device_node *dp) { struct device_node *ap = of_find_node_by_path("/aliases"); + enum su_type rc = SU_PORT_PORT; if (ap) { const char *keyb = of_get_property(ap, "keyboard", NULL); const char *ms = of_get_property(ap, "mouse", NULL); + struct device_node *match; if (keyb) { - if (dp == of_find_node_by_path(keyb)) - return SU_PORT_KBD; + match = of_find_node_by_path(keyb); + + /* + * The pointer is used as an identifier not + * as a pointer, we can drop the refcount on + * the of__node immediately after getting it. + */ + of_node_put(match); + + if (dp == match) { + rc = SU_PORT_KBD; + goto out; + } } if (ms) { - if (dp == of_find_node_by_path(ms)) - return SU_PORT_MS; + match = of_find_node_by_path(ms); + + of_node_put(match); + + if (dp == match) { + rc = SU_PORT_MS; + goto out; + } } } - return SU_PORT_PORT; +out: + of_node_put(ap); + return rc; } static int su_probe(struct platform_device *op) -- 2.19.1