From patchwork Fri Jun 9 11:41:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 773821 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3wkgQn0tBfz9s7m for ; Fri, 9 Jun 2017 21:43:13 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="OtyJazB7"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751543AbdFILnM (ORCPT ); Fri, 9 Jun 2017 07:43:12 -0400 Received: from mail-wr0-f173.google.com ([209.85.128.173]:33118 "EHLO mail-wr0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751531AbdFILlq (ORCPT ); Fri, 9 Jun 2017 07:41:46 -0400 Received: by mail-wr0-f173.google.com with SMTP id v104so30041828wrb.0 for ; Fri, 09 Jun 2017 04:41:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IMND6lqoW9KpvA6HbZb01uZKCB0Epdn5eP8C9Bxoi+E=; b=OtyJazB7yADUY5z6J1qYVxEia/0qbW+5Ay0ifEHv760I2aQ/Qoo2ESiZkPfWUSlp3E yttm24iCCyogTlr150BvpcbO1c27dENcybTYh0EUdWij8eaCSRCGDexkTLlqxYMJvBVV IsqzwHv0+y5YDzj6jhDnOpEeBjy5U391qsOVkI0U8WGRp2SuiE7dO29FzhdUBcNoeIka cVfNUtECAKz6TjQIF5nJlyk0ylObuL/jIjLS7Oy8KPV7pMqyOKUaYJSodlUP1rwo9GBl lN6c0gzTvga07v4IgHJa6BM+xz+BJCtTTSMoSzkZhtgVLo8o1RNu1ZPV9ZxhSGXsOc9Z AKhw== 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=IMND6lqoW9KpvA6HbZb01uZKCB0Epdn5eP8C9Bxoi+E=; b=WSFd8RQ41RdBA8ykIngUBAQSaTtz6ZMp2NDdR6d8yxN+Wjin2fdsm4w2uaDil+dSRz QW8NGRUR9AS/CmxPWyf7at4rmaUvXP8rVr9euX53XEagHPL/ajdXw0KX5/l6alW5Rcom pZf8LLGxqoKtpSt6POv1/tCQDL/3mb0FskAvI/mbJ8rPy7NDtynbxmdnVpfC+tZohyla MB9JNNKb96isrW2Rsp/FVDkFUb9P9V3GixGKc1cKVTdByMTs/mD9VjN3OMLAW0tvKWQB M41VhTLKGt2rcH/C8TbD56SkN7i3HJSaeduHv6QAhRWv2ZDXdh1YNnBPKQIogy12w3kQ jfyg== X-Gm-Message-State: AODbwcAt4ffh1rDV5a942t7nPqpICZhWNRjb+QunSjI8rWEG6wUhpZql tyFu3JgV2Nbks0zCmdQqBQ== X-Received: by 10.28.216.194 with SMTP id p185mr5906951wmg.37.1497008504822; Fri, 09 Jun 2017 04:41:44 -0700 (PDT) Received: from bgdev-debian.lan (dynamic-194-228-20-36.ipv4.broadband.iol.cz. [194.228.20.36]) by smtp.gmail.com with ESMTPSA id r186sm1237510wmr.30.2017.06.09.04.41.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Jun 2017 04:41:44 -0700 (PDT) From: Bartosz Golaszewski To: Andy Shevchenko , Linus Walleij , Alexandre Courbot , Bamvor Jian Zhang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v3 4/8] gpio: mockup: improve readability Date: Fri, 9 Jun 2017 13:41:28 +0200 Message-Id: <1497008492-14907-5-git-send-email-brgl@bgdev.pl> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1497008492-14907-1-git-send-email-brgl@bgdev.pl> References: <1497008492-14907-1-git-send-email-brgl@bgdev.pl> Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org We currently shift bits here and there without actually explaining what we're doing. Add some helper variables with names indicating their purpose to improve the code readability. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index d95d37a..0cb6cba 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -27,6 +27,11 @@ #define GPIO_MOCKUP_NAME "gpio-mockup" #define GPIO_MOCKUP_MAX_GC 10 +/* + * We're storing two values per chip: the GPIO base and the number + * of GPIO lines. + */ +#define GPIO_MOCKUP_MAX_RANGES (GPIO_MOCKUP_MAX_GC * 2) enum { GPIO_MOCKUP_DIR_OUT = 0, @@ -62,7 +67,7 @@ struct gpio_mockup_dbgfs_private { int offset; }; -static int gpio_mockup_ranges[GPIO_MOCKUP_MAX_GC << 1]; +static int gpio_mockup_ranges[GPIO_MOCKUP_MAX_RANGES]; static int gpio_mockup_params_nr; module_param_array(gpio_mockup_ranges, int, &gpio_mockup_params_nr, 0400); @@ -329,23 +334,24 @@ static int gpio_mockup_add(struct device *dev, static int gpio_mockup_probe(struct platform_device *pdev) { - struct gpio_mockup_chip *chips; + int ret, i, base, ngpio, num_chips; struct device *dev = &pdev->dev; - int ret, i, base, ngpio; + struct gpio_mockup_chip *chips; char *chip_name; if (gpio_mockup_params_nr < 2 || (gpio_mockup_params_nr % 2)) return -EINVAL; - chips = devm_kzalloc(dev, - sizeof(*chips) * (gpio_mockup_params_nr >> 1), - GFP_KERNEL); + /* Each chip is described by two values. */ + num_chips = gpio_mockup_params_nr / 2; + + chips = devm_kzalloc(dev, sizeof(*chips) * num_chips, GFP_KERNEL); if (!chips) return -ENOMEM; platform_set_drvdata(pdev, chips); - for (i = 0; i < gpio_mockup_params_nr >> 1; i++) { + for (i = 0; i < num_chips; i++) { base = gpio_mockup_ranges[i * 2]; if (base == -1)