From patchwork Mon Nov 13 10:20:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 10056341 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6848A60365 for ; Mon, 13 Nov 2017 15:48:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A5EB292A1 for ; Mon, 13 Nov 2017 15:48:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4ED8C29321; Mon, 13 Nov 2017 15:48:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BF7F429321 for ; Mon, 13 Nov 2017 15:48:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DA7CE6E65B; Mon, 13 Nov 2017 15:48:15 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-lf0-x241.google.com (mail-lf0-x241.google.com [IPv6:2a00:1450:4010:c07::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 87C876E53C for ; Mon, 13 Nov 2017 10:20:50 +0000 (UTC) Received: by mail-lf0-x241.google.com with SMTP id a2so17682994lfh.11 for ; Mon, 13 Nov 2017 02:20:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=QWRK6vdcVHGADYVPw9pj87PPVnKntpKTEJSd2vJfmi0=; b=IMQYts1TTKkOm6THnt5rvfI797BkyhCa/U7mYFlfeuvGlXjNHEvgEq1/1lGxfMkgZO 8Xm3z2yW4GRdlF0OkkLwDAFZsal1JTHRFPOuhDIMZOC8JgMM6xbNp2tdRCUfTqsT5eSN VvgqP6IGWHmi60slLV4pYCjeGiQhS+RF0UYPJnoccBcfuoLfUnTK/mgaN/4/ewsqyFK2 Ts1inFiuTl01dek5Zz9TDHU3jJ5qJPKmEikwgkbme4f0NTxKFNgyAIm5raHwoNg4/i8B RbGuybpfB5FoHg+a9S/66lvV+dibwP2RcN6+14s6VqSSCTv7pCZ9P2+VPBD8EHSvHYo+ lysA== 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; bh=QWRK6vdcVHGADYVPw9pj87PPVnKntpKTEJSd2vJfmi0=; b=KggSfN7pxjNvbtmxqGtXYPfePUcpIBo3+AMdDhrwNrLqQigv8VGzi++1Z4pXtEYNCr JYCuRnvugnlkiaGkG9omsEymCN4n7d+vkmedhvQ/p6gx6PMERqBuL28ca4Gt9cVc3ra1 VxlTBaYmfdkPztRwKaqQv68zdEJTLXR2Lg8V75Dx7++IdP66UmYZTMIV57eKQcT/2GtT Z8IFjQIadRSgvNnWKritP/cCkabuL01FhM/QHOkFrsJduTlsm2jTpwPBJUgzLoeWTrFf /TSMi/5YJjR0x2gOnEffCaSeFLs6YUNXgFhMas6lii/HG3pvIm9JhRewKZwqtSoazpqs XIfQ== X-Gm-Message-State: AJaThX5yiBl0RFeonIqFkDHO5an9utsRVcl1vqPgcBxdox+BAH0jO1qI L0AZ5YrPg/q1FcXOT60snyiZZDOH X-Google-Smtp-Source: AGs4zMZf5DrIp1SRUJln+14ebJXVaqlwaB1Gi+Iw8E9eaPBr/iuRb1Y4atgT/mhZG5URvvbs5Ip2eQ== X-Received: by 10.25.215.79 with SMTP id o76mr3285469lfg.67.1510568448673; Mon, 13 Nov 2017 02:20:48 -0800 (PST) Received: from xi.terra (c-c0bae655.07-184-6d6c6d4.cust.bredbandsbolaget.se. [85.230.186.192]) by smtp.gmail.com with ESMTPSA id u19sm2810476lfc.89.2017.11.13.02.20.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Nov 2017 02:20:47 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.89) (envelope-from ) id 1eEBrK-0002RQ-82; Mon, 13 Nov 2017 11:20:54 +0100 From: Johan Hovold To: Lee Jones Subject: [PATCH 1/3] backlight: as3711_bl: fix device-tree node lookup Date: Mon, 13 Nov 2017 11:20:47 +0100 Message-Id: <20171113102049.9342-1-johan@kernel.org> X-Mailer: git-send-email 2.15.0 X-Mailman-Approved-At: Mon, 13 Nov 2017 15:48:14 +0000 Cc: Daniel Thompson , Jingoo Han , Johan Hovold , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, stable , linux-fbdev@vger.kernel.org, Guennadi Liakhovetski X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Fix child-node lookup during probe, which ended up searching the whole device tree depth-first starting at the parent rather than just matching on its children. To make things worse, the parent mfd node was also prematurely freed. Note that the nodes returned from the two calls to of_parse_phandle() are also leaking, but fixing that is a bit more involved as pointers to node fields are being stored for later use. Fixes: 59eb2b5e57ea ("drivers/video/backlight/as3711_bl.c: add OF support") Cc: stable # 3.10 Cc: Guennadi Liakhovetski Signed-off-by: Johan Hovold --- drivers/video/backlight/as3711_bl.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/drivers/video/backlight/as3711_bl.c b/drivers/video/backlight/as3711_bl.c index 734a9158946b..21ce56053c88 100644 --- a/drivers/video/backlight/as3711_bl.c +++ b/drivers/video/backlight/as3711_bl.c @@ -262,15 +262,16 @@ static int as3711_bl_register(struct platform_device *pdev, static int as3711_backlight_parse_dt(struct device *dev) { struct as3711_bl_pdata *pdata = dev_get_platdata(dev); - struct device_node *bl = - of_find_node_by_name(dev->parent->of_node, "backlight"), *fb; + struct device_node *bl, *fb; int ret; + bl = of_get_child_by_name(dev->parent->of_node, "backlight"); if (!bl) { dev_dbg(dev, "backlight node not found\n"); return -ENODEV; } + /* FIXME: need to drop reference to returned node */ fb = of_parse_phandle(bl, "su1-dev", 0); if (fb) { pdata->su1_fb = fb->full_name; @@ -279,9 +280,10 @@ static int as3711_backlight_parse_dt(struct device *dev) if (pdata->su1_max_uA <= 0) ret = -EINVAL; if (ret < 0) - return ret; + goto err_put_bl; } + /* FIXME: need to drop reference to returned node */ fb = of_parse_phandle(bl, "su2-dev", 0); if (fb) { int count = 0; @@ -292,7 +294,7 @@ static int as3711_backlight_parse_dt(struct device *dev) if (pdata->su2_max_uA <= 0) ret = -EINVAL; if (ret < 0) - return ret; + goto err_put_bl; if (of_find_property(bl, "su2-feedback-voltage", NULL)) { pdata->su2_feedback = AS3711_SU2_VOLTAGE; @@ -314,8 +316,10 @@ static int as3711_backlight_parse_dt(struct device *dev) pdata->su2_feedback = AS3711_SU2_CURR_AUTO; count++; } - if (count != 1) - return -EINVAL; + if (count != 1) { + ret = -EINVAL; + goto err_put_bl; + } count = 0; if (of_find_property(bl, "su2-fbprot-lx-sd4", NULL)) { @@ -334,8 +338,10 @@ static int as3711_backlight_parse_dt(struct device *dev) pdata->su2_fbprot = AS3711_SU2_GPIO4; count++; } - if (count != 1) - return -EINVAL; + if (count != 1) { + ret = -EINVAL; + goto err_put_bl; + } count = 0; if (of_find_property(bl, "su2-auto-curr1", NULL)) { @@ -355,11 +361,20 @@ static int as3711_backlight_parse_dt(struct device *dev) * At least one su2-auto-curr* must be specified iff * AS3711_SU2_CURR_AUTO is used */ - if (!count ^ (pdata->su2_feedback != AS3711_SU2_CURR_AUTO)) - return -EINVAL; + if (!count ^ (pdata->su2_feedback != AS3711_SU2_CURR_AUTO)) { + ret = -EINVAL; + goto err_put_bl; + } } + of_node_put(bl); + return 0; + +err_put_bl: + of_node_put(bl); + + return ret; } static int as3711_backlight_probe(struct platform_device *pdev)