Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5642745imm; Mon, 27 Aug 2018 01:24:33 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZajMHdXtc6X1D/97WL9keihEV/uToRSFjHrFd4L6on/LkmoIv8MXUPCAlgfVM0avDWjQQ/ X-Received: by 2002:a63:440a:: with SMTP id r10-v6mr11494585pga.417.1535358273845; Mon, 27 Aug 2018 01:24:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535358273; cv=none; d=google.com; s=arc-20160816; b=FipruDqZE9t0Y2ggspQuIdyTNc6Q5PKe5vIgTafCPndMj+pInthErOPSoUUZWm3/mz 03BAoAm5B9zJnfUsPof2GHdosZX70S6d/EWoC65XlQtUyzGPlhI8XsbTyecUcXpQs9gZ fwQHQCO5Uv/9qM2DJhcyxLCILoJInHN182xGxhGCpsrsD41KLSWNLbn+FZF9uWr4wfSW o6o7IU2GcOT5PamgcACx9xyCa4gBhuooW9xNBy6b4GieNvbFRwBS8wueZ2E1daNwfCdo 3uQwhexOVGexq49BSSjHkssn/YMmP6zkuIeYj/TNxD6WumFUlssaujSKKPLwACE+YfNo lHyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=tUtlDobmS3JDO74Woysr6AQvtZDWk+5XonLlWqwCnoc=; b=jAqOMDlYSWSD6OoWQ9Jl0G/La+tToh0L78eOfUv/iqXp8mZPJuW1+8muqLMWuewLJL GDlxHWF148VFqKjy/6r2ijHFC03upymzj5TA6FL1BBuzXWA+fhO6gjzcBEf0fpjcGFsk wbT/CbBrYHMv2F1nmKEZE1a+cjZxwXkQRi2wKDMGH2iYTBAhzWut5fQzbuUNMLyubZWd 56onxy+0NSojUjGlul3Vts3pkmPfp+3TlhvYpfNrLXYOme6lFGRFBcmjg4w84JV/6S/N oZzfWBumR4IOiXauySMK31SMVcqtMurh9guqCqzdbuZPeD8eWCji4Ku/Ei4wh2vk7SQc jW3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=cEZ5FJeB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b25-v6si13502039pgf.545.2018.08.27.01.24.19; Mon, 27 Aug 2018 01:24:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=cEZ5FJeB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727247AbeH0MIP (ORCPT + 99 others); Mon, 27 Aug 2018 08:08:15 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:40229 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727160AbeH0MIO (ORCPT ); Mon, 27 Aug 2018 08:08:14 -0400 Received: by mail-lf1-f68.google.com with SMTP id x26-v6so9179427lfi.7; Mon, 27 Aug 2018 01:22:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=tUtlDobmS3JDO74Woysr6AQvtZDWk+5XonLlWqwCnoc=; b=cEZ5FJeBH/pymft7uNHHILvTUKOtYpJMvyOV7SmSoDb5iNsUoQG8jIAoRlw6dilNfy iatPiJnZmdQr10vLeP/zoAJM8Kl8IBecqiwKT3+ATnPxiIOVoqXQg1HQ6ucnpmdmq0NU hPZKSQLUWYN/s++YPNTZUcdbKwVg+owPLfxdXjzLCwMhQ4e553UFtUAeicoxo8pErPTj NEx9+AglqJ7Y0Hn1R3cjAqhVS85RwZJoKt3+VjS3N5l0Tv5scwVYWG8zFFfrWDpqTUN0 0LXEvWW+RVnAtSfryE/80sB1FO3K54w0lArWU6qnlkCuHhcRR65QC7K0hx9XRD+ITFeA cw1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=tUtlDobmS3JDO74Woysr6AQvtZDWk+5XonLlWqwCnoc=; b=K5WhggqC1XuVYLm67bpYCi1XppEs1mXkA+QEYidaRdq8JpdMWdBQWTvjb7dXfx+phj ugfxOKxEyk31jJDul9LdnptU6P9HzzzhkSRk8ujw6+UxkcGxJGyKGvIH7oEmUEreW6tI P9LAaI4sT8WAyTiXmC4Ags2DPL0gsk5akDk8ERnxl+BzROSNmhFDqwk5B0Y6yf50xOM2 8lDPMmhVuk+Q0E4d2gwN2KJ2iCvRoiecBI2J+t/GlwAcZc7jcqUZWH6UQkx+iCdNnYpc 4dsmh+62mygkihHXAh4d8TTlVo10F1IQFJv5Sv3c1yzYnIJFr6zKKqkTk4v6u7q7dv2I SRNA== X-Gm-Message-State: APzg51AQNB8Ck9rfPWXu3optRVt2zsNNepxWH4MOPOQUAR5P7s20cDkp VyqLC2gJ8j7FrPHvn01V5vRPwG+y X-Received: by 2002:a19:1517:: with SMTP id l23-v6mr8125142lfi.69.1535358156052; Mon, 27 Aug 2018 01:22:36 -0700 (PDT) Received: from xi.terra ([85.230.190.116]) by smtp.gmail.com with ESMTPSA id m15-v6sm2405292ljb.87.2018.08.27.01.22.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Aug 2018 01:22:31 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.91) (envelope-from ) id 1fuCn6-0005sX-NH; Mon, 27 Aug 2018 10:22:28 +0200 From: Johan Hovold To: Rob Herring , Greg Kroah-Hartman Cc: Frank Rowand , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable , Junzhi Zhao , Philipp Zabel , CK Hu , David Airlie Subject: [PATCH v2 2/9] drm/mediatek: fix OF sibling-node lookup Date: Mon, 27 Aug 2018 10:21:46 +0200 Message-Id: <20180827082153.22537-3-johan@kernel.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180827082153.22537-1-johan@kernel.org> References: <20180827082153.22537-1-johan@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use the new of_get_compatible_child() helper to lookup the sibling instead of using of_find_compatible_node(), which searches the entire tree from a given start node and thus can return an unrelated (i.e. non-sibling) node. This also addresses a potential use-after-free (e.g. after probe deferral) as the tree-wide helper drops a reference to its first argument (i.e. the parent device node). While at it, also fix the related cec-node reference leak. Fixes: 8f83f26891e1 ("drm/mediatek: Add HDMI support") Cc: stable # 4.8 Cc: Junzhi Zhao Cc: Philipp Zabel Cc: CK Hu Cc: David Airlie Signed-off-by: Johan Hovold --- drivers/gpu/drm/mediatek/mtk_hdmi.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_hdmi.c b/drivers/gpu/drm/mediatek/mtk_hdmi.c index 2d45d1dd9554..643f5edd68fe 100644 --- a/drivers/gpu/drm/mediatek/mtk_hdmi.c +++ b/drivers/gpu/drm/mediatek/mtk_hdmi.c @@ -1446,8 +1446,7 @@ static int mtk_hdmi_dt_parse_pdata(struct mtk_hdmi *hdmi, } /* The CEC module handles HDMI hotplug detection */ - cec_np = of_find_compatible_node(np->parent, NULL, - "mediatek,mt8173-cec"); + cec_np = of_get_compatible_child(np->parent, "mediatek,mt8173-cec"); if (!cec_np) { dev_err(dev, "Failed to find CEC node\n"); return -EINVAL; @@ -1457,8 +1456,10 @@ static int mtk_hdmi_dt_parse_pdata(struct mtk_hdmi *hdmi, if (!cec_pdev) { dev_err(hdmi->dev, "Waiting for CEC device %pOF\n", cec_np); + of_node_put(cec_np); return -EPROBE_DEFER; } + of_node_put(cec_np); hdmi->cec_dev = &cec_pdev->dev; /* -- 2.18.0