Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2175800imm; Sat, 15 Sep 2018 10:47:15 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdal0FQJa4f2XT+m2KZeqt+rUvfnmsST+EpZUgwEdBnpYMlutB0BMumtpeeEkemaA3yceSwp X-Received: by 2002:a62:cdcf:: with SMTP id o198-v6mr18388002pfg.12.1537033635347; Sat, 15 Sep 2018 10:47:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537033635; cv=none; d=google.com; s=arc-20160816; b=jYQs+jNZMXur5KVv6s3ApnfP7LH7zJ8YOhvnmJ0H8FAjmkktAKBLje5MD7mFgRjwjd CfItqoVOC2nWeaMo9lK6F16XjR2q+FSFtIBlLxJ7Fyb2tmB/pLvqQlR0XzdbJ6vhL3RQ gyU4wUeBMxHwPaN7BpsUnhkhAwSEFJczM1PrOqbyV7Ag5iFTpYDBi5/2RB38e9EepRBM kQ/lCcm5F60LODYOk7x2oHfdaiouVgPeD5KCYEPvDRoJJ8mPd9QDQspMwL+cCIs9LErj 73yMyOx7IpHNPTZhNX8C2f6GiIHC+9Hof6Zd1OzVPnjIbNQBMXphqECpNFlj9MEi/rSQ p0mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=L/eeXoJ2tdf/zTRRrynwm9J5HH2dofi+d09wyXHyjXI=; b=a6KQ0TwRbUwovPK7HCaKRR4EQ23Pa4KBiyeL8PrrVObTYAVl3qtNUpYdfWbjy83PXk hPS0ZJZS8LDE6Sn9ud/+ifWpiXv70nxSwaODebuOkqJu2FyVMQdXjIvpndnVQ2DtI8bx kKBxk+fp11iVKK4ADPxXSawvm5Zq5k/NF4sH08FnbUiO6ho10OX5Un/wCtwC0sV/DDr5 Lhl9r04nXzWdy7INz83v8155PfUBNZRbZRcF8EXW4fnUkFLhE+EjL5HmItG9Lc10d81C TEtnzkuKkaN6+aBRhqzMooHLaLM6v9LNiJUTQiSoojRFg/bAy5NP3Nguddrld21wA5kt qhHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=F+UlGq9b; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l15-v6si10776264pgj.528.2018.09.15.10.47.00; Sat, 15 Sep 2018 10:47:15 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=F+UlGq9b; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727691AbeIOXGd (ORCPT + 99 others); Sat, 15 Sep 2018 19:06:33 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:42485 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727225AbeIOXGc (ORCPT ); Sat, 15 Sep 2018 19:06:32 -0400 Received: by mail-pl1-f195.google.com with SMTP id g23-v6so5563298plq.9; Sat, 15 Sep 2018 10:46:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=L/eeXoJ2tdf/zTRRrynwm9J5HH2dofi+d09wyXHyjXI=; b=F+UlGq9bZyI7aIoGBt8G4BnvhbX+uUYo6f6/ZRbA0e2E7/7rrK3dhqmqZJJW9VYmkt g4VOSrv5q02NMuSoha6eDfcOiOSdv/7HzTe31yz5nFYjMMk+XhNYOstRSg74blW6sVml hVYGuVaVRpPXzQRj72Gi6J7NkYwniWP9VLIQ36RySkmlOLk1Z1olUILbJIWmboNGxQ4f y0phLmg6Ozy1IJtIb2uVOv1mVo3vX6tAZZNEFxtkTBjaeCNru/dea0qR4ldZdewopfsf esSan3Z4vqE75SyMwELHlswsjtjK7zepuqaqde69hu2YYAMQ4V0gNu80np+f/9Pjtrwu oDug== 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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=L/eeXoJ2tdf/zTRRrynwm9J5HH2dofi+d09wyXHyjXI=; b=cdd2yQRp35f43rtvQb0DItRhHakzoUvdVsgi3dQucDrQSE5V4FfFs958ZoXuyGK9QG jSyFIwHsAqgB3R6RZIarzzX57K1tIehMPjcmnqG1KUuQuF2Yy3g1gkT18ml7wFd73lQN iW8jH8ADP3HW2jUOr3ogf7DTI2+8MB1TB80CiPKEGAQd73+3Yp9/tMZ+kpfR+tbGCy37 utK2HzaaKT7r4d1qjoxO5sA06dQTBgXW+WVExVjqcFOm/7DiyxyAZfi2iHyyS+BYqg7B HEl+eu+FCe+++3cV2HsFZEQaSoBtvrC29If2aLtujbCUyAyhtbctB1HxQxIYHtNnHkNo YGNQ== X-Gm-Message-State: APzg51AKMbMDFLCeecerm4L4VG0DAtP2gmyC+UTdLr5WNmTSLNKy6Rqf ME/yNxQBmMkHJkEhhH7DN3U= X-Received: by 2002:a17:902:246a:: with SMTP id m39-v6mr17281940plg.57.1537033606126; Sat, 15 Sep 2018 10:46:46 -0700 (PDT) Received: from himanshu-Vostro-3559 ([103.233.116.134]) by smtp.gmail.com with ESMTPSA id l3-v6sm12653249pff.8.2018.09.15.10.46.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 15 Sep 2018 10:46:45 -0700 (PDT) Date: Sat, 15 Sep 2018 23:16:34 +0530 From: Himanshu Jha To: YueHaibing Cc: peda@axentia.se, jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Julia.Lawall@lip6.fr Subject: Re: [PATCH -next] iio: potentiometer: mcp4531: merge calls to of_match_device and of_device_get_match_data Message-ID: <20180915174634.GA15225@himanshu-Vostro-3559> References: <20180915105430.24052-1-yuehaibing@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180915105430.24052-1-yuehaibing@huawei.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Sep 15, 2018 at 06:54:30PM +0800, YueHaibing wrote: > Drop call to of_match_device, which is subsumed by the subsequent > call to of_device_get_match_data. The code becomes simpler, and a > temporary variable can be dropped. > > Found by coccinelle. > > Signed-off-by: YueHaibing Already applied! https://lore.kernel.org/lkml/20180819201752.2280be76@archlinux/ Anyway, if you want to work on making similar changes, you may refer the following cocci script: I tested[1] the changes through 0-day and had few false positives and regressions. Therefore, check the results and compile test the changes before sending patches. Julia, and I had tried to make the confidence "High" but few cases were difficult to resolve, and later neither of us had time to look back at it again. Not all maintainers will acknowledge such a change, but IIRC Rob Herring gave a thumbs up on few cases on the dt-mailing list. [1] https://github.com/himanshujha199640/linux-next/commit/efb7ed923bd00c86fe0a4e67e2ddb636ff0e0ff4 --------------------------------------------------------------------- /// Use of_device_get_match_data() to get matched data in an OF driver //# of_device_get_match_data() returns const * and therefore the left //# argument of assignment should also be a const * for compatible //# types. /// // Confidence: Moderate // Copyright: (C) 2018 Himanshu Jha, GPLv2. // Copyright: (C) 2018 Julia Lawall, INRIA/LIP6. GPLv2. // Keywords: of_match_device, of_device_get_match_data virtual patch virtual context virtual org virtual report @r1 depends on patch && !context && !org && !report@ expression x,y,z; identifier match; type T; statement S; @@ - match = of_match_device(x, y); ( - if(match==NULL) S - z = match->data; + z = of_device_get_match_data(y); | - if(match==NULL) S - z = (T *)match->data; + z = of_device_get_match_data(y); | - if(match==NULL) S - z = (T)match->data; + z = (T)of_device_get_match_data(y); | - if(match!= NULL) - z = match->data; + z = of_device_get_match_data(y); | - if(match!= NULL) - z = (T *)match->data; + z = of_device_get_match_data(y); | - if(match!= NULL) - z = (T)match->data; + z = (T)of_device_get_match_data(y); ) ... when != match @r2 depends on r1 && patch && !context && !org && !report@ type T1; expression e; identifier r1.match; @@ ( - T1 match = e; | - T1 match; ) // ---------------------------------------------------------------------------- @r1_context depends on !patch && (context || org || report)@ type T; identifier match; statement S; expression x, y, z; position j0, j1; @@ * match@j0 = of_match_device(x, y); ( * if(match==NULL) S * z = match@j1->data; | * if(match==NULL) S * z = (T *)match@j1->data; | * if(match==NULL) S * z = (T)match@j1->data; | * if(match!= NULL) * z = match@j1->data; | * if(match!= NULL) * z = (T *)match@j1->data; | * if(match!= NULL) * z = (T)match@j1->data; ) ... when != match @r2_context depends on r1 && !patch && (context || org || report)@ type T1; identifier r1_context.match; expression e; position j0; @@ ( * T1 match@j0 = e; | * T1 match@j0; ) // ---------------------------------------------------------------------------- @script:python r1_org depends on org@ j0 << r1_context.j0; j1 << r1_context.j1; @@ msg = "WARNING: opportunity for of_device_get_match_data." coccilib.org.print_todo(j0[0], msg) coccilib.org.print_link(j1[0], "") // ---------------------------------------------------------------------------- @script:python r1_report depends on report@ j0 << r1_context.j0; j1 << r1_context.j1; @@ msg = "WARNING: opportunity for of_device_get_match_data around line %s." % (j1[0].line) coccilib.report.print_report(j0[0], msg) --------------------------------------------------------------------- Thanks -- Himanshu Jha Undergraduate Student Department of Electronics & Communication Guru Tegh Bahadur Institute of Technology