Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2510617imm; Mon, 24 Sep 2018 05:41:46 -0700 (PDT) X-Google-Smtp-Source: ACcGV62vK4hkKDM9YjxlifLk6ZK42YkoFtQAOqIPyiuI5STS0awFEBMUlNaNVM/RHgv21sHOuBLp X-Received: by 2002:a65:5c46:: with SMTP id v6-v6mr1481633pgr.21.1537792906406; Mon, 24 Sep 2018 05:41:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537792906; cv=none; d=google.com; s=arc-20160816; b=bs9nOTIUC65t2uU+6l+fpMMIW9akA2I8DVPwWVeQt8efbUkJFBhRrOxXAo3umOo/ki AMJhEgk/moAQGHXlDCTuPHbjayJ5rmxf2hEkuaR/rQL9h0CSmRBQw0ILgDG7TyGTFcX6 echsmvRJzc3WwkCiMpG4a19ZF693wuakA181EFzyOA1sNmqa5odiWWQJwFZHHptU1FT1 J59JmZzFw2RIYbMSR+U9SHm4M+z/WISIJPYRxIJUreapn877nMgKURx0ec/nF6in/qY8 SU8RcKpXRA6DyzLynPF5LBdKD3gzfotSb3np3jZt1fC8H849kKtucM8b9AXYoBE5RA1l E0nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=jHLGR+bProG3ij1vy7UVMd0Eu4GcKzEKy3MZndtzl1A=; b=jOUFa6xMWWiShERdhmdfbnqzgEuIkdS/uP8409TvcUEqfF1SwIYTmJILKxZ4fNrSCj F5+wwjkrkbWFZQciuRYMA5iM2b2T74yCIWPNexQMQqLATTObcCs0cBWMSeCOWhmfOWb4 gZI52ny3La4oW2UmnUqRhvMos2PEwwkHwElJHVUZtodccdOcDRV1MBPgBwHyVDkXjDGG 7FtIbggrVrv8XQay+4UpCsnt/mFuC0KV3oDnkN9Mas7rTRiWx7sUHEh7IYZTuEDdds6Z JVx6ZAraOFf9FoKQfoVOkam4YdKlF0CaxMXDinfLrkqWeM+HaQb0jrVnMiNRijPoiFD/ aRBA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y22-v6si32462793pgj.436.2018.09.24.05.41.30; Mon, 24 Sep 2018 05:41:46 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388455AbeIXSlP (ORCPT + 99 others); Mon, 24 Sep 2018 14:41:15 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:58828 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387912AbeIXSlO (ORCPT ); Mon, 24 Sep 2018 14:41:14 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 7766A1092; Mon, 24 Sep 2018 12:39:16 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Carlo Caione , Martin Blumenstingl , Ulf Hansson , Johan Hovold Subject: [PATCH 4.18 145/235] mmc: meson-mx-sdio: fix OF child-node lookup Date: Mon, 24 Sep 2018 13:52:11 +0200 Message-Id: <20180924113120.036334624@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180924113103.999624566@linuxfoundation.org> References: <20180924113103.999624566@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Johan Hovold commit c483a5cc9d09f4ceaa9abb106f863cc89cb643d9 upstream. Use the new of_get_compatible_child() helper to lookup the slot child node 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-child) 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 node of the device being probed). While at it, also fix up the related slot-node reference leak. Fixes: ed80a13bb4c4 ("mmc: meson-mx-sdio: Add a driver for the Amlogic Meson8 and Meson8b SoCs") Cc: stable # 4.15 Cc: Carlo Caione Cc: Martin Blumenstingl Cc: Ulf Hansson Acked-by: Martin Blumenstingl Signed-off-by: Johan Hovold Signed-off-by: Ulf Hansson Signed-off-by: Greg Kroah-Hartman --- drivers/mmc/host/meson-mx-sdio.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/drivers/mmc/host/meson-mx-sdio.c +++ b/drivers/mmc/host/meson-mx-sdio.c @@ -517,19 +517,23 @@ static struct mmc_host_ops meson_mx_mmc_ static struct platform_device *meson_mx_mmc_slot_pdev(struct device *parent) { struct device_node *slot_node; + struct platform_device *pdev; /* * TODO: the MMC core framework currently does not support * controllers with multiple slots properly. So we only register * the first slot for now */ - slot_node = of_find_compatible_node(parent->of_node, NULL, "mmc-slot"); + slot_node = of_get_compatible_child(parent->of_node, "mmc-slot"); if (!slot_node) { dev_warn(parent, "no 'mmc-slot' sub-node found\n"); return ERR_PTR(-ENOENT); } - return of_platform_device_create(slot_node, NULL, parent); + pdev = of_platform_device_create(slot_node, NULL, parent); + of_node_put(slot_node); + + return pdev; } static int meson_mx_mmc_add_host(struct meson_mx_mmc_host *host)