Received: by 10.213.65.68 with SMTP id h4csp1319520imn; Mon, 19 Mar 2018 00:16:32 -0700 (PDT) X-Google-Smtp-Source: AG47ELu+wZ187b+LmyanyWnsaxqC7QDX9isVXzFlK3S4Ekc8MZZvhexdOOb9ux4QLn9Mv8/GVx7z X-Received: by 10.98.34.75 with SMTP id i72mr9295973pfi.165.1521443792024; Mon, 19 Mar 2018 00:16:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521443791; cv=none; d=google.com; s=arc-20160816; b=o0DGE3WH6OfKPMrtg3ex9/O5PBD8ZZ5D7X04hyFl4YYep3Lnbt4o6mhMbJcvvteRVK XR4jGfsfigAx9hADVogBV5rQq5jWfioh1I28mYfq+fd9/ZtF9lOSX88Zq8OQcwuEMllO 9DfO9nJjIb7tVAiy9eXWgSrFVV92QgUKPsa8nLRuLb0S9+dCAs00NTlVvCJCScPRWXcZ xCWZvRdHQcLnsBEeCjqtEMbcVmZaGKcj+r0S4kNOAhSNTkNiPf5BNUmu6kvqop9Rg0t1 w+w8wWlJCdKeKpn5OhPgmlcJ3B4a7lvlFjHjd9vRRODO5ENEweh9RcKNBY7HKPopdv88 l8Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=kxP1FkMmRj0PieX4Pzpy79sd82Cvm1D3LRBjD+4WwaE=; b=JfWESCvKop0xgpS0JotwwGJmwTsqYDt24sBY7HFAvEgQxSLLnwbzFRZii3CIsclKba vEdQVPqzBVyyI0dypTqmtBy8DJKqCqSfBDBGx7ZPO1HRenFvaoKTrziwzVsk2rE8012t lOI//DjRhVJFNq6WTGbCYf0NSVTdIokS7TD+HvE9On48Y2ZBJyjzQOACd/ygOFpVEy5O kdtx7yhAglfUj5GMPb+PTY3/0B9QXxCA7PJ0mHmPRen51bGNi9ijMvb451qMnNhthnLH 6JEaq9IPDioo9OOuqvB2WK+hNUZwNa2y9dbdjJovZg7PBy850zQb/xN+pNjKnJQCiYJb 5icA== 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 m189si1165904pfb.130.2018.03.19.00.16.17; Mon, 19 Mar 2018 00:16:31 -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 S1755333AbeCSHO6 (ORCPT + 99 others); Mon, 19 Mar 2018 03:14:58 -0400 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:13567 "EHLO mail2-relais-roc.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755164AbeCSHOz (ORCPT ); Mon, 19 Mar 2018 03:14:55 -0400 X-IronPort-AV: E=Sophos;i="5.48,329,1517871600"; d="scan'208";a="318729739" Received: from abo-3-110-68.mrs.modulonet.fr (HELO [192.168.0.15]) ([85.68.110.3]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Mar 2018 08:14:53 +0100 Date: Mon, 19 Mar 2018 08:14:53 +0100 (CET) From: Julia Lawall X-X-Sender: jll@hadrien To: Arushi Singhal cc: daniel.vetter@intel.com, Gustavo Padovan , Sean Paul , David Airlie , Ben Skeggs , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, nouveau@lists.freedesktop.org, outreachy-kernel@googlegroups.com Subject: Re: [Outreachy kernel] [PATCH] gpu: drm: Use list_{next/prev}_entry instead of list_entry In-Reply-To: <20180319050530.GA25589@seema-Inspiron-15-3567> Message-ID: References: <20180319050530.GA25589@seema-Inspiron-15-3567> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 19 Mar 2018, Arushi Singhal wrote: > This patch replace list_entry with list_{next/prev}_entry as it makes > the code more clear to read. > Done using coccinelle: > > @@ > expression e1; > identifier e3; > type t; > @@ > ( > - list_entry(e1->e3.next,t,e3) > + list_next_entry(e1,e3) > | > - list_entry(e1->e3.prev,t,e3) > + list_prev_entry(e1,e3) > ) This looks like a rule that could be nice for the Linux kernel in general, because the code really is much simpler. I would suggest to write the rule in a more robust way, as follows: @@ identifier e3; type t; t *e1; @@ ( - list_entry(e1->e3.next,t,e3) + list_next_entry(e1,e3) | - list_entry(e1->e3.prev,t,e3) + list_prev_entry(e1,e3) ) @@ expression e1; identifier e3; @@ ( - list_entry(e1->e3.next,typeof(*e1),e3) + list_next_entry(e1,e3) | - list_entry(e1->e3.prev,typeof(*e1),e3) + list_prev_entry(e1,e3) This checks that the type that is specified corresponds to the one on e1. It could actually be that the call is getting the first element of a list, from some different type, and coincidentally the two types have the same field name for the list element. Unfortunately, the second rule, with the typeof call, doesn't currently work in Coccinelle, because the semantic patch language doesn't actually support typeof, and thinks that it is a function call. I will fix this. To make a semantic patch for the kernel, you can try running spgen on the above file and answer the questions that it asks. You can find examples in the coccinelle/scripts directory. Just run spgen foo.cocci Then answer the questions. Then run spgen foo.cocci > foo_for_kernel.cocci The second run will use the results of the first run to print the semantic patch. Let me know if you have any questions. You can always adjust the semantic patch that is generated by hand afterwards if needed. julia > > Signed-off-by: Arushi Singhal > --- > drivers/gpu/drm/drm_lease.c | 2 +- > drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c > index 1402c0e..4dcfb5f 100644 > --- a/drivers/gpu/drm/drm_lease.c > +++ b/drivers/gpu/drm/drm_lease.c > @@ -340,7 +340,7 @@ static void _drm_lease_revoke(struct drm_master *top) > break; > > /* Over */ > - master = list_entry(master->lessee_list.next, struct drm_master, lessee_list); > + master = list_next_entry(master, lessee_list); > } > } > } > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c > index e4c8d31..81c3567 100644 > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c > @@ -134,7 +134,7 @@ nvkm_cstate_find_best(struct nvkm_clk *clk, struct nvkm_pstate *pstate, > nvkm_volt_map(volt, volt->max2_id, clk->temp)); > > for (cstate = start; &cstate->head != &pstate->list; > - cstate = list_entry(cstate->head.prev, typeof(*cstate), head)) { > + cstate = list_prev_entry(cstate, head)) { > if (nvkm_cstate_valid(clk, cstate, max_volt, clk->temp)) > break; > } > -- > 2.7.4 > > -- > You received this message because you are subscribed to the Google Groups "outreachy-kernel" group. > To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe@googlegroups.com. > To post to this group, send email to outreachy-kernel@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20180319050530.GA25589%40seema-Inspiron-15-3567. > For more options, visit https://groups.google.com/d/optout. >