Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2422484imu; Sun, 13 Jan 2019 01:35:47 -0800 (PST) X-Google-Smtp-Source: ALg8bN7EyAs5XkdVW8xYJoiy8itfuhH3nVpHTwiWVzmbAJ3X7TdRiE/FrGV+RfOKw4HV3jygvL3o X-Received: by 2002:a62:4c5:: with SMTP id 188mr21521054pfe.130.1547372147362; Sun, 13 Jan 2019 01:35:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547372147; cv=none; d=google.com; s=arc-20160816; b=v699lm/m8t3cD0UzfDJ7gyKM/xDWoqXN28KlXesnV7i0ykBslb32Kuhi/LIrpdYWv8 9uHpWQrtYUHKjKJosonoJuuw1jE/L2RceMAFMSyipuQcvXjuKyEln+iw0XsemQXWIexu UOhWm7BvpHV0GNN0hdae3NJfqZtt4iyokzxbdaqxJ1oaxe63lm7J7rs4kga6SGqisLo8 8UJhwx4wfp8rWl1rwW2EOFq+A18qbRv6pFrCMJqdi7Lp7L3TYqHAKYml2Wc3CGgMcecI 6b9hx+c7u7L6ue8hM1fH1qSb4hr+WBlKvhOmxHYY2G/CXPmzsfjkv+KwdklGPdMGbv0B cO4A== 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; bh=Tqivxa7OzWkac19a3sjPCZhVTVfA1K2/pInh/3rM3hk=; b=zTk2KutNUJPy5CXOfvX/RLnnLiaC7PeNlnosqhyWj82Z4r1vrtc/Pg4d2Q+fN9DQD6 10gZdsX/Yhfg9+KEyfkR5T5JuNwhazDkxKcKk9kJWu6nAvOi9NrnoZ1fh27Wbp7pvOKK 7BN4mHJVuTAm+ZFBakf9XcYFbMSuxBytTMlZxaL7aYdErbuiiFc+C/5gczZMVOKDkZaz PJxPApOooYv0tce0bHS5FRMlG9n89sG3zPnHs0gf6J0LYiyFTOrKwVBYaiQYzU9gXjF1 d0zr5Yvc+kFfP4Qcqv5mBYd+otNM/ITOKt1cJiNParZunp5ycdhsLgA+o+truRKYM1Z/ kcbw== 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 k19si35995470pgn.20.2019.01.13.01.35.30; Sun, 13 Jan 2019 01:35:47 -0800 (PST) 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 S1726623AbfAMJZH (ORCPT + 99 others); Sun, 13 Jan 2019 04:25:07 -0500 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:60664 "EHLO mail3-relais-sop.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726522AbfAMJYu (ORCPT ); Sun, 13 Jan 2019 04:24:50 -0500 X-IronPort-AV: E=Sophos;i="5.56,473,1539640800"; d="scan'208";a="291725800" Received: from palace.lip6.fr ([132.227.105.202]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/AES128-SHA256; 13 Jan 2019 10:24:46 +0100 From: Julia Lawall To: Philipp Zabel Cc: kernel-janitors@vger.kernel.org, David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] drm/imx: imx-ldb: add missing of_node_puts Date: Sun, 13 Jan 2019 09:47:42 +0100 Message-Id: <1547369264-24831-3-git-send-email-Julia.Lawall@lip6.fr> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1547369264-24831-1-git-send-email-Julia.Lawall@lip6.fr> References: <1547369264-24831-1-git-send-email-Julia.Lawall@lip6.fr> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The device node iterators perform an of_node_get on each iteration, so a jump out of the loop requires an of_node_put. Move the initialization channel->child = child; down to just before the call to imx_ldb_register so that intervening failures don't need to clear it. Add a label at the end of the function to do all the of_node_puts. The semantic patch that finds part of this problem is as follows (http://coccinelle.lip6.fr): // @@ expression root,e; local idexpression child; iterator name for_each_child_of_node; @@ for_each_child_of_node(root, child) { ... when != of_node_put(child) when != e = child ( return child; | * return ...; ) ... } // Signed-off-by: Julia Lawall --- This changes the semantics, with respect to the availability of the child field, and has not been tested. drivers/gpu/drm/imx/imx-ldb.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/imx/imx-ldb.c b/drivers/gpu/drm/imx/imx-ldb.c index 2c5bbe3..e31e263 100644 --- a/drivers/gpu/drm/imx/imx-ldb.c +++ b/drivers/gpu/drm/imx/imx-ldb.c @@ -643,8 +643,10 @@ static int imx_ldb_bind(struct device *dev, struct device *master, void *data) int bus_format; ret = of_property_read_u32(child, "reg", &i); - if (ret || i < 0 || i > 1) - return -EINVAL; + if (ret || i < 0 || i > 1) { + ret = -EINVAL; + goto free_child; + } if (!of_device_is_available(child)) continue; @@ -657,7 +659,6 @@ static int imx_ldb_bind(struct device *dev, struct device *master, void *data) channel = &imx_ldb->channel[i]; channel->ldb = imx_ldb; channel->chno = i; - channel->child = child; /* * The output port is port@4 with an external 4-port mux or @@ -667,13 +668,13 @@ static int imx_ldb_bind(struct device *dev, struct device *master, void *data) imx_ldb->lvds_mux ? 4 : 2, 0, &channel->panel, &channel->bridge); if (ret && ret != -ENODEV) - return ret; + goto free_child; /* panel ddc only if there is no bridge */ if (!channel->bridge) { ret = imx_ldb_panel_ddc(dev, channel, child); if (ret) - return ret; + goto free_child; } bus_format = of_get_bus_format(dev, child); @@ -689,18 +690,26 @@ static int imx_ldb_bind(struct device *dev, struct device *master, void *data) if (bus_format < 0) { dev_err(dev, "could not determine data mapping: %d\n", bus_format); - return bus_format; + ret = bus_format; + goto free_child; } channel->bus_format = bus_format; + channel->child = child; ret = imx_ldb_register(drm, channel); - if (ret) - return ret; + if (ret) { + channel->child = NULL; + goto free_child; + } } dev_set_drvdata(dev, imx_ldb); return 0; + +free_child: + of_node_put(child); + return ret; } static void imx_ldb_unbind(struct device *dev, struct device *master,