From patchwork Mon Aug 19 08:49:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 171596 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp2680948ily; Mon, 19 Aug 2019 01:49:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqwHqtP7iJfTdF1cVxrLprn+YpB/ZFFhI7iWdCyjXN4z5N6aI+2l8ICDs6t5ewyTYFVr2vr8 X-Received: by 2002:a63:e84a:: with SMTP id a10mr19700621pgk.274.1566204551004; Mon, 19 Aug 2019 01:49:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566204550; cv=none; d=google.com; s=arc-20160816; b=s2FEn3a1Ns1lZzJ9m6uvSndOVq6ay2UFotQkNOV0vJK+A4mKmMeeit9DfNwZcuznqK HzXTi9cH3QleotUV5lZIqQaQcxEjEvfi/7yQhXrx5Q+b+b3nfLjgbBV/BRHUWjtZoUfn LUM4gnJ99qxVqPxskbHCv3IiYBL3botJBpmNUFmreLbluZ20tWWpcwNNarQRcXvcl22y zP4aMpz4eC+0MmVnPrkIVBHy/KI89oH5L/aF0VmLqlB0egaMOtnmQyzdVH/c0LwXHffs Z3r/Lx9RB/VLir6l5GQ197GH1mj1DTLI41C2kLnKpo1g7P+1WJnxLcOSYgfOgMH0yGk6 5f8w== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=ZsQfLpei7nj2tl+B7srXcwekQFx0RlmqVNmiItyNH/w=; b=i0UXDi74DcR0vb89ex9vgKDuRpLJiu/A7gspVTYMNZ62UlR6QasGzFn4NumH+OrPQ9 hAJ1XUoDA8rb4qZJw8OIWBEyTYFsdhT/iSaraW7LnQcAtjYYVFioNXKtPDBcdbAk1jIL ePl8noRHTI+VdYxqMQU4cPnW4GFuOHfELCrbJkxfsm9QHuem2dYVxMm8ZMzK8/g+75JB mk5lKHvQEL7kqbJke8W8AU9c/90NJ8UVWNbS25RH/G6XPGvUIqJM8dUZs9m++YMVTlrS 5OKYkXFRB0Ky1vKyMOrc+sdio+5aL7ftJwCq7sTPVpHp04rknMPvOPSadoe5TqOoZcVD 5hHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GbFlVw+n; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-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 y3si8202309pgp.19.2019.08.19.01.49.10; Mon, 19 Aug 2019 01:49:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-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=GbFlVw+n; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-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 S1726186AbfHSItK (ORCPT + 5 others); Mon, 19 Aug 2019 04:49:10 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:37237 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725768AbfHSItK (ORCPT ); Mon, 19 Aug 2019 04:49:10 -0400 Received: by mail-lj1-f194.google.com with SMTP id t14so986941lji.4 for ; Mon, 19 Aug 2019 01:49:08 -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:mime-version :content-transfer-encoding; bh=ZsQfLpei7nj2tl+B7srXcwekQFx0RlmqVNmiItyNH/w=; b=GbFlVw+nGjx9GyheQhUtckeHf0k12rGScL0ZbVj8CnglKrgF90thar4K8R9Ri57I3T D12bKH41Ebb1h7zF5Sy+qSdKvmXeWwuG23n9MfsjvolstLQbTqEMg5BX5DXNmCj2w5BH jNFI3si200j5l5bHpWvUUmvgWYCDUDnSvMr810cCu32UprgjGyEwbRgHkvIerDO5KKqq j+kLIODm9Dy5VUipnd/7B+tksJ2Z/jjByBUNDsTLZNNJ9rIkqbtNMaiOl5SgptVyugB+ iR3Tm+L/+c1kEeDPo4Ok5RKfNLvVALR4XC9ZGNEeHgjeFEOstlxF3oC/SKPcM0wDJqXq v0ug== 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:mime-version :content-transfer-encoding; bh=ZsQfLpei7nj2tl+B7srXcwekQFx0RlmqVNmiItyNH/w=; b=Ty5Whjc4yI/EbrjPjM75SW0pgqeoR0JWTBt9LvS94OM39Fk/GNvACH3YOPo90b/Z+z +AkZjRYQ01470/jm+i9rJ53rDuDR8G271fDtlM1jc7G/4G4mWCT9mPGHY6qMjpM44VD+ K9stHkDAR++E4jjtSFl9U5vQ35uJ6TKS7Z5wbOS1f5Ugne+V2z3JFDDkSdbTPwxh5D31 Vc4CCu/xe7f6thqT3GJ88qnNY+NR8YjP538djntkwFuPTA2lXe59KwtpWmrQSHQFRMQS uykdpXV/i9Kd9w0H3YQZ97UESUFgHT7909hQgv5vQyAAmsuUc9t/deYdGd8oPzlnvcDX 7Tsw== X-Gm-Message-State: APjAAAX1VY2iiCDd2ShZUp0flDrBvX2NjlfHdP9Q2mFzAraH04EkwMWK 7OYbZmwP/SbhkJUF4aVBEnzIm69kiRs= X-Received: by 2002:a2e:968e:: with SMTP id q14mr11124845lji.195.1566204547858; Mon, 19 Aug 2019 01:49:07 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id f6sm2215391lja.16.2019.08.19.01.49.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2019 01:49:06 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org Cc: Bartosz Golaszewski , Linus Walleij , Stephen Boyd , Bjorn Andersson Subject: [PATCH] gpio: Pass mask and size with the init_valid_mask() Date: Mon, 19 Aug 2019 10:49:04 +0200 Message-Id: <20190819084904.30027-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org It is more helpful for drivers to have the affected fields directly available when we use the callback to set up the valid mask. Change this and switch over the only user (MSM) to use the passed parameters. If we do this we can also move the mask out of publicly visible struct fields. Cc: Stephen Boyd Cc: Bjorn Andersson Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 8 +++++--- drivers/pinctrl/qcom/pinctrl-msm.c | 19 ++++++++++--------- include/linux/gpio/driver.h | 4 +++- 3 files changed, 18 insertions(+), 13 deletions(-) -- 2.21.0 Reviewed-by: Stephen Boyd diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 5277b8f1ff7c..22b87c6e8cd5 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -375,10 +375,12 @@ static int gpiochip_alloc_valid_mask(struct gpio_chip *gc) return 0; } -static int gpiochip_init_valid_mask(struct gpio_chip *gpiochip) +static int gpiochip_init_valid_mask(struct gpio_chip *gc) { - if (gpiochip->init_valid_mask) - return gpiochip->init_valid_mask(gpiochip); + if (gc->init_valid_mask) + return gc->init_valid_mask(gc, + gc->valid_mask, + gc->ngpio); return 0; } diff --git a/drivers/pinctrl/qcom/pinctrl-msm.c b/drivers/pinctrl/qcom/pinctrl-msm.c index 7f35c196bb3e..a5d8f75da4a7 100644 --- a/drivers/pinctrl/qcom/pinctrl-msm.c +++ b/drivers/pinctrl/qcom/pinctrl-msm.c @@ -593,24 +593,25 @@ static void msm_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) #define msm_gpio_dbg_show NULL #endif -static int msm_gpio_init_valid_mask(struct gpio_chip *chip) +static int msm_gpio_init_valid_mask(struct gpio_chip *gc, + unsigned long *valid_mask, + unsigned int ngpios) { - struct msm_pinctrl *pctrl = gpiochip_get_data(chip); + struct msm_pinctrl *pctrl = gpiochip_get_data(gc); int ret; unsigned int len, i; - unsigned int max_gpios = pctrl->soc->ngpios; const int *reserved = pctrl->soc->reserved_gpios; u16 *tmp; /* Driver provided reserved list overrides DT and ACPI */ if (reserved) { - bitmap_fill(chip->valid_mask, max_gpios); + bitmap_fill(valid_mask, ngpios); for (i = 0; reserved[i] >= 0; i++) { - if (i >= max_gpios || reserved[i] >= max_gpios) { + if (i >= ngpios || reserved[i] >= ngpios) { dev_err(pctrl->dev, "invalid list of reserved GPIOs\n"); return -EINVAL; } - clear_bit(reserved[i], chip->valid_mask); + clear_bit(reserved[i], valid_mask); } return 0; @@ -622,7 +623,7 @@ static int msm_gpio_init_valid_mask(struct gpio_chip *chip) if (ret < 0) return 0; - if (ret > max_gpios) + if (ret > ngpios) return -EINVAL; tmp = kmalloc_array(len, sizeof(*tmp), GFP_KERNEL); @@ -635,9 +636,9 @@ static int msm_gpio_init_valid_mask(struct gpio_chip *chip) goto out; } - bitmap_zero(chip->valid_mask, max_gpios); + bitmap_zero(valid_mask, ngpios); for (i = 0; i < len; i++) - set_bit(tmp[i], chip->valid_mask); + set_bit(tmp[i], valid_mask); out: kfree(tmp); diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index 72d48a2bab65..dc03323897ef 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -363,7 +363,9 @@ struct gpio_chip { void (*dbg_show)(struct seq_file *s, struct gpio_chip *chip); - int (*init_valid_mask)(struct gpio_chip *chip); + int (*init_valid_mask)(struct gpio_chip *chip, + unsigned long *valid_mask, + unsigned int ngpios); int base; u16 ngpio;