Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3104661imm; Sun, 19 Aug 2018 12:19:22 -0700 (PDT) X-Google-Smtp-Source: AA+uWPz+8s6XjmiycMjMvFf4jRrYgNSKo2VYMAy/gmQGxg3f7nATf/sNB3T25FTyDmT/rDyz5HjC X-Received: by 2002:a63:fd06:: with SMTP id d6-v6mr40480603pgh.348.1534706362541; Sun, 19 Aug 2018 12:19:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534706362; cv=none; d=google.com; s=arc-20160816; b=gqtxaj5eSwZz+5ms7kgjEAQniTKHWlGKGngKwT1ggakyj2O0g4dsH3EMUbFdm0OHGe l5+iwdnJrauzcNGfCWGiuphS9L8z5OfQu18h220vvMRUDy4fMQdB+8ig6RdGjc8XGbhQ ewuuoW4D2xk/5u30S6Z5k7bCZxJsDgWIatL8lIuIqZraWrEWgh6WK0Xn2nkjjqfUiUG/ M9Np2kndUpMZHYqxRCBz7LrPP/lp8n4HWLLw11GrYzSht3Cv+4hA/frT3bZtUFUGyJif QHs6vTvAtawQlRV4+bph0doro5QZM6EO6i1ucTdwPZe7em/7ibyKtRAR9utcb/A82cfv xDPQ== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=x9rkqX2RCc3bzaQCboZ4vv/O4J3ZkSIP6T1dlEgOenA=; b=PpOW/2DiVqjxisolyCyn8xvolT9NC4B47hAmtl59BojOmetg1LaEbPMbeV+zfAaWOq PII1ezhSJa21RgDzM88wkFrl+FQt4thmGcnpDjCPc9IccFXlgeZiM8kD8OdaF9/Edw9s JoKOQNnJpAEs42tZJ8R5aWLQN0LoEINbikyXJdQTNVtLReRQyon/pCUjrvV9bUhhD8ej BpRsGIHV9/cBxujnI5IEXwfhQD0H9EGz70A1hYCRWZgudo3FHccbmDxQQI0301ZviORZ L0lXzC1BPeGdqK5EpHNolP6zCxlXDoa8RhSy67U6F731fAWq55mOTHVu4n2N9yreq7V0 oKUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jivUtbHo; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a4-v6si7310001pgl.9.2018.08.19.12.19.07; Sun, 19 Aug 2018 12:19:22 -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=@kernel.org header.s=default header.b=jivUtbHo; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726560AbeHSWa3 (ORCPT + 99 others); Sun, 19 Aug 2018 18:30:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:55596 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725830AbeHSWa3 (ORCPT ); Sun, 19 Aug 2018 18:30:29 -0400 Received: from archlinux (cpc91196-cmbg18-2-0-cust659.5-4.cable.virginm.net [81.96.234.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3BDF920C0C; Sun, 19 Aug 2018 19:17:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1534706276; bh=mRsRPA6Tpd3bJlq51o3UbNTJMEdp8MLKH9uFc5Y6qZQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=jivUtbHoJKc0yiysVM1zsRxKAURZvrhn/+1glOBij2qMrGEVOO/5bZ3NaAun4jI0y WRFfS64yXawXu6RCkhdk73E3siPnxMQkEw9ehbZfTeIa3/COqaggsJKgIWLmoARnSw a4Pq0U3SPEhIqmwBZ51IP96vNLfFdAv8S7A4qVW8= Date: Sun, 19 Aug 2018 20:17:52 +0100 From: Jonathan Cameron To: Peter Rosin Cc: Julia Lawall , Peter Meerwald-Stadler , kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Lars-Peter Clausen , Hartmut Knaack , Himanshu Jha Subject: Re: [PATCH 3/3] iio: potentiometer: merge calls to of_match_device and of_device_get_match_data Message-ID: <20180819201752.2280be76@archlinux> In-Reply-To: <0a8aff9e-51fe-96a5-bcab-cc472be92dcc@axentia.se> References: <1526896150-27134-1-git-send-email-Julia.Lawall@lip6.fr> <1526896150-27134-4-git-send-email-Julia.Lawall@lip6.fr> <0a8aff9e-51fe-96a5-bcab-cc472be92dcc@axentia.se> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 19 Aug 2018 09:02:42 +0200 Peter Rosin wrote: > On 2018-05-21 11:49, Julia Lawall 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. > > > > The semantic match that makes this change is as follows: > > (http://coccinelle.lip6.fr/) > > > > // > > @r@ > > local idexpression match; > > identifier i; > > expression x, dev, e, e1; > > @@ > > - match@i = of_match_device(x, dev); > > - if (match) e = of_device_get_match_data(dev); > > - else e = e1; > > + e = of_device_get_match_data(dev); > > + if (!e) e = e1; > > > > @@ > > identifier r.i; > > @@ > > - const struct of_device_id *i; > > ... when != i > > // > > > > Signed-off-by: Julia Lawall > > Reviewed-by: Peter Rosin Applied to the togreg branch of iio.git. Glad you replied to this one Peter, it had definitely dropped through the cracks. Jonathan > > Cheers, > Peter > > > > > --- > > drivers/iio/potentiometer/max5481.c | 7 ++----- > > drivers/iio/potentiometer/mcp4018.c | 7 ++----- > > drivers/iio/potentiometer/mcp4531.c | 7 ++----- > > 3 files changed, 6 insertions(+), 15 deletions(-) > > > > diff --git a/drivers/iio/potentiometer/mcp4018.c b/drivers/iio/potentiometer/mcp4018.c > > index 320a7c9..c051ee0 100644 > > --- a/drivers/iio/potentiometer/mcp4018.c > > +++ b/drivers/iio/potentiometer/mcp4018.c > > @@ -147,7 +147,6 @@ static int mcp4018_probe(struct i2c_client *client) > > struct device *dev = &client->dev; > > struct mcp4018_data *data; > > struct iio_dev *indio_dev; > > - const struct of_device_id *match; > > > > if (!i2c_check_functionality(client->adapter, > > I2C_FUNC_SMBUS_BYTE)) { > > @@ -162,10 +161,8 @@ static int mcp4018_probe(struct i2c_client *client) > > i2c_set_clientdata(client, indio_dev); > > data->client = client; > > > > - match = of_match_device(of_match_ptr(mcp4018_of_match), dev); > > - if (match) > > - data->cfg = of_device_get_match_data(dev); > > - else > > + data->cfg = of_device_get_match_data(dev); > > + if (!data->cfg) > > data->cfg = &mcp4018_cfg[i2c_match_id(mcp4018_id, client)->driver_data]; > > > > indio_dev->dev.parent = dev; > > diff --git a/drivers/iio/potentiometer/mcp4531.c b/drivers/iio/potentiometer/mcp4531.c > > index df894af..d87ca85 100644 > > --- a/drivers/iio/potentiometer/mcp4531.c > > +++ b/drivers/iio/potentiometer/mcp4531.c > > @@ -360,7 +360,6 @@ static int mcp4531_probe(struct i2c_client *client) > > struct device *dev = &client->dev; > > struct mcp4531_data *data; > > struct iio_dev *indio_dev; > > - const struct of_device_id *match; > > > > if (!i2c_check_functionality(client->adapter, > > I2C_FUNC_SMBUS_WORD_DATA)) { > > @@ -375,10 +374,8 @@ static int mcp4531_probe(struct i2c_client *client) > > i2c_set_clientdata(client, indio_dev); > > data->client = client; > > > > - match = of_match_device(of_match_ptr(mcp4531_of_match), dev); > > - if (match) > > - data->cfg = of_device_get_match_data(dev); > > - else > > + data->cfg = of_device_get_match_data(dev); > > + if (!data->cfg) > > data->cfg = &mcp4531_cfg[i2c_match_id(mcp4531_id, client)->driver_data]; > > > > indio_dev->dev.parent = dev; > > diff --git a/drivers/iio/potentiometer/max5481.c b/drivers/iio/potentiometer/max5481.c > > index ffe2761..6d2f13f 100644 > > --- a/drivers/iio/potentiometer/max5481.c > > +++ b/drivers/iio/potentiometer/max5481.c > > @@ -137,7 +137,6 @@ static int max5481_probe(struct spi_device *spi) > > struct iio_dev *indio_dev; > > struct max5481_data *data; > > const struct spi_device_id *id = spi_get_device_id(spi); > > - const struct of_device_id *match; > > int ret; > > > > indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*data)); > > @@ -149,10 +148,8 @@ static int max5481_probe(struct spi_device *spi) > > > > data->spi = spi; > > > > - match = of_match_device(of_match_ptr(max5481_match), &spi->dev); > > - if (match) > > - data->cfg = of_device_get_match_data(&spi->dev); > > - else > > + data->cfg = of_device_get_match_data(&spi->dev); > > + if (!data->cfg) > > data->cfg = &max5481_cfg[id->driver_data]; > > > > indio_dev->name = id->name; > > >