Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp120389imm; Mon, 21 May 2018 03:21:21 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpzvTBUfXrPKhshX4rsVg0oSgXEiwfVTEvUgUp7LmGt8Gz4fuG1uM23GKtSDjugTUX8q3Ua X-Received: by 2002:a17:902:bd46:: with SMTP id b6-v6mr19881647plx.170.1526898081217; Mon, 21 May 2018 03:21:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526898081; cv=none; d=google.com; s=arc-20160816; b=EPLPsSIdmFcdIm8250Q++AZjoYtZX4jlRqzDCtpijRvPZ6616VjM4ZaXrdqXvBtyc3 UI9W/RklXror92+BqmKEEO/Mdl9yz3gu6QZ8E+XbFLeEmdmD+wKmtTtYdZ1YFWpX9lAh wv2nqcwNJJCFxr4rw28Jm4Ch4qoRiueU+MSG2EkLwn076KU3dNxS/pz++rPI5CIOEvH/ mB2Du6AoCUWKMekNaa+5eedpejVBLrRUVcjTuJ1+SJ5MBTKnQtnzyE9ylS2JwuuIsj6e wvw6VyTACdr0DN3P4UCXjmT0jo1AJssmnNDxTOfBrjsjXHezI4g7W0mpe6C1BmF4X2GV IL3g== 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:arc-authentication-results; bh=cV1KxX53nqSEvxL/yvzeWLCxbPY1sfYsXNuG1ptmU8I=; b=mB/Khxtv05M4qmPPaJD2mJYWG6yJQU2NScevUvSptRZ+MPYEGrkh9c7jlzH++3dU/Y 79Cce5lw8pt7n4/s/tSmGzmSFao3OAmPjilz4DuZ8Hux5GWeO/3TejPJOlL1l/TOCXcf VKPcoQWfflnqmF1OqQp7ZqrgGZtFKQXFOLJH2wdZuivKESpord5ftb5BEqSMmLwvkIza yExLUOcI76q4dZ2Gi9jOJkUarHwwvhFNB7zUwdslBzPPvt7GxsegXk9CCl1N2UOtjw67 ne6/BgkXviQnSgq1Qc65LqFYTOTl9CnYXFVz8XRbwQUSDp4xhl98YxXO90K2Wi9A30CS 0H4A== 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 e1-v6si10955826pgr.167.2018.05.21.03.21.05; Mon, 21 May 2018 03:21:21 -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 S1752642AbeEUKUy (ORCPT + 99 others); Mon, 21 May 2018 06:20:54 -0400 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:35615 "EHLO mail2-relais-roc.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751597AbeEUKUw (ORCPT ); Mon, 21 May 2018 06:20:52 -0400 X-IronPort-AV: E=Sophos;i="5.49,426,1520895600"; d="scan'208";a="327708875" Received: from palace.rsr.lip6.fr (HELO localhost.localdomain) ([132.227.105.202]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/AES128-SHA256; 21 May 2018 12:20:48 +0200 From: Julia Lawall To: Peter Meerwald-Stadler Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Lars-Peter Clausen , Hartmut Knaack , Jonathan Cameron , Peter Rosin , Himanshu Jha Subject: [PATCH 3/3] iio: potentiometer: merge calls to of_match_device and of_device_get_match_data Date: Mon, 21 May 2018 11:49:10 +0200 Message-Id: <1526896150-27134-4-git-send-email-Julia.Lawall@lip6.fr> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1526896150-27134-1-git-send-email-Julia.Lawall@lip6.fr> References: <1526896150-27134-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 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 --- 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;