Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3019262pxv; Mon, 12 Jul 2021 07:27:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmeMmYELV++JYrtGzNdvnnOoxR+jQ7g+tgrbRNpPNHYVJTwemaMeOHHpO9vQ/mEWeewVbQ X-Received: by 2002:a6b:c90f:: with SMTP id z15mr30781743iof.183.1626100021296; Mon, 12 Jul 2021 07:27:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626100021; cv=none; d=google.com; s=arc-20160816; b=ERDkHwLN2wIZAifY/3b2n6OZAnqLvJufG37ca8pQSvpacCZwk680oJnou9to6MO13s qxluqNylq97WMwQRJp0hwRo0OaW86pd6Lz6fPhCL3wYYsA8jW0LyupkBXDBtgc6Zb6LV 3/a1SyAHaZ0Q7/bA1AD4Tl8u69D1Sc/lgRR0qM/KEop0Ihjg3MfzrH8eRi/M4DbCr1Pv icWRIFVXJt9xGX1l7y0yMqpOEy9KtbbeqDpugKU5jlNpyECG7TVp1t5gsUQV22FUfwqt cYrbCwX+NQFVzxmMfpNSTBhKspkwv4v3XCw+hhHpYggVR81Vp3mGYrUOkicocHW8kZZ+ zXww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature; bh=lhrZD67b45ok4ysvAU2S6ZIKtsWTYc9YLH5eVabdcKc=; b=w8rxOp6esKHcMvr4flBf/CHyjuXE6FfUDgT9z4HsfVi33r9GTIa1PuRgRdVOzDi4t7 M1D6eNt8DBdzmhG6w7z5W0O6sWoYbfBT6tqhaxdaRgffuJc/C9JX6XK7a+AEp1CK6V6E w7pPtm1ePSSL8TYSsSX3FYy2nTh8R6ktgjaJ8E4iuKquc7BjzYMuZ4bNrf/hyEgDgezi LddKO2dLcL2IC/nz3Ade6yMNRy3wdGoGwzosoLXxdTMKqAcHfnmuqjIbHeyEsp/a9YbA dvBHCBPnlIdouh8uzmTAZLL4oHsZvqeJlBqW1Ei6mCtmXrW2LvZCN5Nc0ib81ku4NFi4 Jl5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=XGziL+Nj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i13si19196335ilm.156.2021.07.12.07.26.49; Mon, 12 Jul 2021 07:27:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=XGziL+Nj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234940AbhGLO2e (ORCPT + 99 others); Mon, 12 Jul 2021 10:28:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234333AbhGLO2d (ORCPT ); Mon, 12 Jul 2021 10:28:33 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF8B4C0613DD for ; Mon, 12 Jul 2021 07:25:44 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id p8so25899208wrr.1 for ; Mon, 12 Jul 2021 07:25:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=lhrZD67b45ok4ysvAU2S6ZIKtsWTYc9YLH5eVabdcKc=; b=XGziL+Njv0FnQe3+dd3+FvcAuLySoyuxlEHAkFVYmot6FHU1Nlqn9plIYketzMq7Mb Z+TMR0HQk5knJUzSyI5x4GYKWkmiey7SaHdSvkbJNSlNWkTZaAa8CQXmQ3tB8/lVKo4E HPrwh9cO0zsmEjhRtftdFrRAY3d6iVSvk+GKc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=lhrZD67b45ok4ysvAU2S6ZIKtsWTYc9YLH5eVabdcKc=; b=oA2E7RXMrtHtN4dT3hPElVLGXYJTOdnrqHnKgCtCAdgyLkDunbNHRNLrOUjOO0RMXA jcS7R4CAbqNzmvUu3wGxyzjQ1ls9hKqmkpnegamnxgoYhNK4HCoFvnKsSf9O/Y6ICNn1 1RGiHxfcjMja5/39j2+RjKHLoV7Q32UN5VQyKKmp84ctNlxQI7untKtCyg9TydMtsRmq KPCvPUuXwTfyRVsBQUWU08fm/juYvYOsWEtia361q3RNkWZlrH1YTv5l2cwzhwRY6y2D 2k1GUd2TiBYLLUnJqEHhWo4ZVe+BGor6YJWc6ReZ3vWbWFTLGf23ylwty0h+aIV0jmVM fhpw== X-Gm-Message-State: AOAM531TJyALoOegJ0wovUwH/VahImIH4ld1LCcdBq6C1vzg9BeLE0sg TMqhT2bSy8vQKCp3ZgSO2dSvUw== X-Received: by 2002:adf:ed08:: with SMTP id a8mr26649274wro.375.1626099943574; Mon, 12 Jul 2021 07:25:43 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id v21sm9209078wml.5.2021.07.12.07.25.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jul 2021 07:25:42 -0700 (PDT) Date: Mon, 12 Jul 2021 16:25:41 +0200 From: Daniel Vetter To: Julia Lawall Cc: Maarten Lankhorst , kernel-janitors@vger.kernel.org, Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] drm/of: free the right object Message-ID: Mail-Followup-To: Julia Lawall , Maarten Lankhorst , kernel-janitors@vger.kernel.org, Maxime Ripard , Thomas Zimmermann , David Airlie , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org References: <20210709200717.3676376-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210709200717.3676376-1-Julia.Lawall@inria.fr> X-Operating-System: Linux phenom 5.10.0-7-amd64 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 09, 2021 at 10:07:17PM +0200, Julia Lawall wrote: > There is no need to free a NULL value. Instead, free the object > that is leaking due to the iterator. > > The semantic patch that finds this problem is as follows: > > // > @@ > expression x,e; > identifier f; > @@ > x = f(...); > if (x == NULL) { > ... when any > when != x = e > * of_node_put(x); > ... > } > // > > Fixes: 6529007522de ("drm: of: Add drm_of_lvds_get_dual_link_pixel_order") > Signed-off-by: Julia Lawall Applied to drm-misc-next, thanks for your patch. Random rant about this for_each_child_of_node(): - not documented with kerneldoc - very dangerous since the seemingly correct usage leaks What we've done here for similar refcounted iterators is a 3 step process: - iter_init() - for_each_iter() macro - iter_fini(), which has to be always called after iter_init and cleans up the last reference. Then it's a lot more obvious that you call iter_fini() when you break out of a loop. Trying to hide that in the for_each macro is a bit much. Cheers, Daniel > > --- > drivers/gpu/drm/drm_of.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/drm_of.c b/drivers/gpu/drm/drm_of.c > index ca04c34e8251..197c57477344 100644 > --- a/drivers/gpu/drm/drm_of.c > +++ b/drivers/gpu/drm/drm_of.c > @@ -315,7 +315,7 @@ static int drm_of_lvds_get_remote_pixels_type( > > remote_port = of_graph_get_remote_port(endpoint); > if (!remote_port) { > - of_node_put(remote_port); > + of_node_put(endpoint); > return -EPIPE; > } > > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch