From patchwork Tue May 30 08:58:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 768486 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 3wcSGC2Y94z9s65 for ; Tue, 30 May 2017 18:59:15 +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="SsQAkCya"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751482AbdE3I7C (ORCPT ); Tue, 30 May 2017 04:59:02 -0400 Received: from mail-wm0-f46.google.com ([74.125.82.46]:34578 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751333AbdE3I6w (ORCPT ); Tue, 30 May 2017 04:58:52 -0400 Received: by mail-wm0-f46.google.com with SMTP id 123so25863065wmg.1 for ; Tue, 30 May 2017 01:58:51 -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=SsQAkCyargbJf0ulXLXNtKdjDsyH++aC6X8nBzA/WrFFFi+7QQqCKLwgnoV8IQ9KyN jRucRJV+NR6mJVAlNx50URM0BYXK+RKCQ4SiXNc+ENX3Xo9RqtVBBxQ/OdhWPCqTeN3j MdUXozAab/BzCxlCwRVw+b6/DdJLprWztY/vxfLwJeeNyQZ32zvET/PdHlf3h8JG2jiq l3G9dLWb7wiG2hknU1B0gj7fpJlqC24T3hoV17DTWBljzIRAuSra0p87VegzFrm/ZcI5 eaViUxw2ffmOnUaiO4pe5nXYiAQnw/Kzbpflj3mNxiBLPKrdNCxLilDXUylnQKwWzPzh uNnA== 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=T9PkEYLBe7Ig2qQx5W9gB2OhGllBy6V16vmvImQKDNFFsVPQeQhrjbLIsM4c9m8EHD 8Ld423aYNY4UxZc8iTVPAnPHnKeEbHu+STxw8KusRApJW82gYW0IyM7+RaGIWQyDS7Ie Dsjz3AeGS8ePVn1ujQmhOkjwiziOyGFj5F2PlVnHU+iZVByxD8Ob6AeuVQaJMcusgdMk ADp62/JKFXF7LM1LlSMDFeN3xqY7bDG/fUMunZF5rNacGmPB1yFf/nCeWJy4+YRfMQKp vOgb957+kgzz4m9NKYri//g7RU2gFPDCHYTy+s6vA3ZLIF3sMMQwPQf+qaFJs9NRbS0O cJGg== X-Gm-Message-State: AODbwcCVfuoJbhYh7mpsJBEuLXGrMNXIKaU7dRsWy7noMsuWwU7Stx71 CJerTiFIj0VJS1jX X-Received: by 10.28.197.11 with SMTP id v11mr880011wmf.84.1496134730474; Tue, 30 May 2017 01:58:50 -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 m14sm30863381wmi.2.2017.05.30.01.58.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 30 May 2017 01:58:49 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Alexandre Courbot , Bamvor Jian Zhang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 4/7] gpio: mockup: improve readability Date: Tue, 30 May 2017 10:58:37 +0200 Message-Id: <1496134720-5363-5-git-send-email-brgl@bgdev.pl> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1496134720-5363-1-git-send-email-brgl@bgdev.pl> References: <1496134720-5363-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)