From patchwork Thu Oct 5 11:03:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 114916 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp456125qgn; Thu, 5 Oct 2017 04:03:42 -0700 (PDT) X-Received: by 10.159.218.9 with SMTP id v9mr22453430plp.182.1507201422829; Thu, 05 Oct 2017 04:03:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507201422; cv=none; d=google.com; s=arc-20160816; b=WyWoOxuAEyC6tB8Fsp9UrVl6Hgt7Dtbx/sYEoviaFSAv9gfDtOHQBqQK+TkZ1l/Ufy FXznuuu1br/0xKWbqzCPWtwmRXJdcCm5v2o4Nn8ALOv4SYhcKWWtVHcj3c8Dh4fOIlUS VtvfS5RTSbYZdCAGYyAWkUaQXR/pwdWY0UGbJPE0njdKWJXlpWV2pz7RuT/jJW65KNd0 A3b8z49krsSYmimUR1FDm4a0PqKh3vIc4UeNuMCyzh8TH1Q5a0YEZDrAZoKyWLgq9pW6 e+tPmBn6oYfD3p3dGqbomHtsmsbOYaL5rRAiBKoJHw3efesiHqSbSEk9vLT1bUERab/H yOOg== 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:dkim-signature:arc-authentication-results; bh=2yF5qj8vTd/zHn3vXJpS1v4+ehrhpTBx2PbihGbWWQQ=; b=tj5uLpHWgOSNxVbPe2WCSXkoMKVYIyL3ow86c9ta2cDN5PU+65mG4d2VCD4/v2rvRb fsxFOjYQT05t7L7aq2Y4vrGlvJKPO4GtBkHI6ePiL6c0h+s+kQPOm2UqZ7Fdo86uJjpG iSZz6gwtQKlVLumnER8Nr8ZRBCsQVHb2TJBQEjRDWfQSd0LUE/F106p8FHJ85ZghzWfV 8CeVZh/u2pSPV38EdQ20QD5Ixv3DhzOhUmyw9dqgQRD/RNG7MFAmzRcgjU2ebyW9bsMC icpOUVjloOwfIdO/PRxIl9pRvmNoTjZA8g1yHvXLLALzhRjGsouHS0T3raAH4eqk69RU lp0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=K/SewmTt; spf=pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-i2c-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y10si1686719plk.155.2017.10.05.04.03.42; Thu, 05 Oct 2017 04:03:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-i2c-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=@linaro.org header.s=google header.b=K/SewmTt; spf=pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-i2c-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751907AbdJELDm (ORCPT + 3 others); Thu, 5 Oct 2017 07:03:42 -0400 Received: from mail-wr0-f179.google.com ([209.85.128.179]:48825 "EHLO mail-wr0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751890AbdJELDl (ORCPT ); Thu, 5 Oct 2017 07:03:41 -0400 Received: by mail-wr0-f179.google.com with SMTP id u5so10398958wrc.5 for ; Thu, 05 Oct 2017 04:03:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2yF5qj8vTd/zHn3vXJpS1v4+ehrhpTBx2PbihGbWWQQ=; b=K/SewmTtXCeUQ9r+MjhzFFp63PYfrWZsKrHaDb39KfIiKbVDb/fJ0SjnXF5YEjrOxn LgvFSCiDltq73py3xfw/ctkRMRQi1oyduQbjMUvhNnVSNWt5CondKUz2bq411IxbiftI HFmgNp+MTDmFltGlWysNtvNGQUTaOgt6mdR1g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=2yF5qj8vTd/zHn3vXJpS1v4+ehrhpTBx2PbihGbWWQQ=; b=dRbxJHL5jKRzGL1gG1cz+54lBHzOtjJRSsOV6S9TSgtvN4sRqPXEwxm6/OVt7Psr+Y gmA3hrYPmis7Gp5H7StGTXE/QeIH9evJWLTQfADtrB+MVG/5t6u756nB/7rE1GwGU9Bu 1FoGOYa1ZmpNO8leVwqFnu/+daGhtGcksoC/DozEYA1Rx20hZGH75Zfcifk4l23yzAQG lGcRD5s2yQafIqedT9cBwXszYXEC4rVht56WhLdtGwKa7v+4opE3FwCa9ECl5Jr9Ztrl L+bw57pfjjZHmqACMr3iAlC+eA3UKkxYz80pVNwfLlxTP4FDpvgGEKmnVnVVTdqsss+x +ffA== X-Gm-Message-State: AHPjjUhnxojBcAZBt9mN/R2+OC0qdASgK76G/05El0rVXXVAKJ0EzkKi oxsT/qWHOU7Gke7tmv+wFtwS1w== X-Google-Smtp-Source: AOwi7QCtJ1AtHAWYebyt//pU/dnGFrvtId3arpyXB3VcLGxRJjT3nAyVfpGYkw91jKGSkE+bqWz0Lg== X-Received: by 10.223.186.67 with SMTP id t3mr23719509wrg.22.1507201420077; Thu, 05 Oct 2017 04:03:40 -0700 (PDT) Received: from genomnajs.local (catv-80-98-18-187.catv.broadband.hu. [80.98.18.187]) by smtp.gmail.com with ESMTPSA id e134sm17336478wma.31.2017.10.05.04.03.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 05 Oct 2017 04:03:39 -0700 (PDT) From: Linus Walleij To: Wolfram Sang , linux-i2c@vger.kernel.org Cc: Linus Walleij Subject: [PATCH 5/7 v3] i2c: gpio: Local vars in probe Date: Thu, 5 Oct 2017 13:03:08 +0200 Message-Id: <20171005110310.5900-6-linus.walleij@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20171005110310.5900-1-linus.walleij@linaro.org> References: <20171005110310.5900-1-linus.walleij@linaro.org> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org By creating local variables for *dev and *np, the code become much easier to read, in my opinion. Tested-by: Geert Uytterhoeven Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Put memcpy on a single line, keeping down the LoC changed I put this at the end of the series because compared to the rest of the patches it is completely unimportant. --- drivers/i2c/busses/i2c-gpio.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) -- 2.13.5 diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c index 97b9c29e9429..a702e493275c 100644 --- a/drivers/i2c/busses/i2c-gpio.c +++ b/drivers/i2c/busses/i2c-gpio.c @@ -88,10 +88,12 @@ static int i2c_gpio_probe(struct platform_device *pdev) struct i2c_gpio_platform_data *pdata; struct i2c_algo_bit_data *bit_data; struct i2c_adapter *adap; + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; enum gpiod_flags gflags; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; @@ -99,16 +101,15 @@ static int i2c_gpio_probe(struct platform_device *pdev) bit_data = &priv->bit_data; pdata = &priv->pdata; - if (pdev->dev.of_node) { - of_i2c_gpio_get_props(pdev->dev.of_node, pdata); + if (np) { + of_i2c_gpio_get_props(np, pdata); } else { /* * If all platform data settings are zero it is OK * to not provide any platform data from the board. */ - if (dev_get_platdata(&pdev->dev)) - memcpy(pdata, dev_get_platdata(&pdev->dev), - sizeof(*pdata)); + if (dev_get_platdata(dev)) + memcpy(pdata, dev_get_platdata(dev), sizeof(*pdata)); } /* @@ -123,7 +124,7 @@ static int i2c_gpio_probe(struct platform_device *pdev) gflags = GPIOD_OUT_HIGH; else gflags = GPIOD_OUT_HIGH_OPEN_DRAIN; - priv->sda = devm_gpiod_get_index(&pdev->dev, NULL, 0, gflags); + priv->sda = devm_gpiod_get_index(dev, NULL, 0, gflags); if (IS_ERR(priv->sda)) { ret = PTR_ERR(priv->sda); /* FIXME: hack in the old code, is this really necessary? */ @@ -142,7 +143,7 @@ static int i2c_gpio_probe(struct platform_device *pdev) gflags = GPIOD_OUT_LOW; else gflags = GPIOD_OUT_LOW_OPEN_DRAIN; - priv->scl = devm_gpiod_get_index(&pdev->dev, NULL, 1, gflags); + priv->scl = devm_gpiod_get_index(dev, NULL, 1, gflags); if (IS_ERR(priv->scl)) { ret = PTR_ERR(priv->scl); /* FIXME: hack in the old code, is this really necessary? */ @@ -173,15 +174,15 @@ static int i2c_gpio_probe(struct platform_device *pdev) bit_data->data = priv; adap->owner = THIS_MODULE; - if (pdev->dev.of_node) - strlcpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name)); + if (np) + strlcpy(adap->name, dev_name(dev), sizeof(adap->name)); else snprintf(adap->name, sizeof(adap->name), "i2c-gpio%d", pdev->id); adap->algo_data = bit_data; adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; - adap->dev.parent = &pdev->dev; - adap->dev.of_node = pdev->dev.of_node; + adap->dev.parent = dev; + adap->dev.of_node = np; adap->nr = pdev->id; ret = i2c_bit_add_numbered_bus(adap); @@ -195,7 +196,7 @@ static int i2c_gpio_probe(struct platform_device *pdev) * get accessors to get the actual name of the GPIO line, * from the descriptor, then provide that instead. */ - dev_info(&pdev->dev, "using lines %u (SDA) and %u (SCL%s)\n", + dev_info(dev, "using lines %u (SDA) and %u (SCL%s)\n", desc_to_gpio(priv->sda), desc_to_gpio(priv->scl), pdata->scl_is_output_only ? ", no clock stretching" : "");