linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Use gpio_is_valid()
@ 2018-04-27 11:43 Arvind Yadav
  2018-04-27 11:44 ` [PATCH 1/2] [media] platform: " Arvind Yadav
  2018-04-27 11:44 ` [PATCH 2/2] [media] sta2x11: Use gpio_is_valid() and remove unnecessary check Arvind Yadav
  0 siblings, 2 replies; 3+ messages in thread
From: Arvind Yadav @ 2018-04-27 11:43 UTC (permalink / raw)
  To: mchehab, hans.verkuil, viro; +Cc: linux-kernel, linux-media

Replace the manual validity checks for the GPIO with the
gpio_is_valid().

Arvind Yadav (2):
  [PATCH 1/2] [media] platform: Use gpio_is_valid()
  [PATCH 2/2] [media] sta2x11: Use gpio_is_valid() and remove unnecessary check

 drivers/media/pci/sta2x11/sta2x11_vip.c | 31 +++++++++++++++----------------
 drivers/media/platform/via-camera.c     |  2 +-
 2 files changed, 16 insertions(+), 17 deletions(-)

-- 
1.9.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] [media] platform: Use gpio_is_valid()
  2018-04-27 11:43 [PATCH 0/2] Use gpio_is_valid() Arvind Yadav
@ 2018-04-27 11:44 ` Arvind Yadav
  2018-04-27 11:44 ` [PATCH 2/2] [media] sta2x11: Use gpio_is_valid() and remove unnecessary check Arvind Yadav
  1 sibling, 0 replies; 3+ messages in thread
From: Arvind Yadav @ 2018-04-27 11:44 UTC (permalink / raw)
  To: mchehab, hans.verkuil, viro; +Cc: linux-kernel, linux-media

Replace the manual validity checks for the GPIO with the
gpio_is_valid().

Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
---
 drivers/media/platform/via-camera.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/via-camera.c b/drivers/media/platform/via-camera.c
index e9a0263..f01c3e8 100644
--- a/drivers/media/platform/via-camera.c
+++ b/drivers/media/platform/via-camera.c
@@ -178,7 +178,7 @@ static int via_sensor_power_setup(struct via_camera *cam)
 
 	cam->power_gpio = viafb_gpio_lookup("VGPIO3");
 	cam->reset_gpio = viafb_gpio_lookup("VGPIO2");
-	if (cam->power_gpio < 0 || cam->reset_gpio < 0) {
+	if (!gpio_is_valid(cam->power_gpio) || !gpio_is_valid(cam->reset_gpio)) {
 		dev_err(&cam->platdev->dev, "Unable to find GPIO lines\n");
 		return -EINVAL;
 	}
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] [media] sta2x11: Use gpio_is_valid() and remove unnecessary check
  2018-04-27 11:43 [PATCH 0/2] Use gpio_is_valid() Arvind Yadav
  2018-04-27 11:44 ` [PATCH 1/2] [media] platform: " Arvind Yadav
@ 2018-04-27 11:44 ` Arvind Yadav
  1 sibling, 0 replies; 3+ messages in thread
From: Arvind Yadav @ 2018-04-27 11:44 UTC (permalink / raw)
  To: mchehab, hans.verkuil, viro; +Cc: linux-kernel, linux-media

Replace the manual validity checks for the GPIO with the
gpio_is_valid().

In vip_gpio_reserve(), Error checking for gpio pin is not correct.
If pwr_pin = -1, It will return 0. This should be return an error.

In sta2x11_vip_init_one(), Error checking for gpio 'reset_pin'
is unnecessary. Because vip_gpio_reserve() is also checking for
valid gpio pin. So removed extra error checking for gpio 'reset_pin'.

Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
---
 drivers/media/pci/sta2x11/sta2x11_vip.c | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c b/drivers/media/pci/sta2x11/sta2x11_vip.c
index dd199bf..069c4a8 100644
--- a/drivers/media/pci/sta2x11/sta2x11_vip.c
+++ b/drivers/media/pci/sta2x11/sta2x11_vip.c
@@ -908,10 +908,10 @@ static int sta2x11_vip_init_controls(struct sta2x11_vip *vip)
 static int vip_gpio_reserve(struct device *dev, int pin, int dir,
 			    const char *name)
 {
-	int ret;
+	int ret = -ENODEV;
 
-	if (pin == -1)
-		return 0;
+	if (!gpio_is_valid(pin))
+		return ret;
 
 	ret = gpio_request(pin, name);
 	if (ret) {
@@ -946,7 +946,7 @@ static int vip_gpio_reserve(struct device *dev, int pin, int dir,
  */
 static void vip_gpio_release(struct device *dev, int pin, const char *name)
 {
-	if (pin != -1) {
+	if (gpio_is_valid(pin)) {
 		dev_dbg(dev, "releasing pin %d (%s)\n",	pin, name);
 		gpio_unexport(pin);
 		gpio_free(pin);
@@ -1003,25 +1003,24 @@ static int sta2x11_vip_init_one(struct pci_dev *pdev,
 	if (ret)
 		goto disable;
 
-	if (config->reset_pin >= 0) {
-		ret = vip_gpio_reserve(&pdev->dev, config->reset_pin, 0,
-				       config->reset_name);
-		if (ret) {
-			vip_gpio_release(&pdev->dev, config->pwr_pin,
-					 config->pwr_name);
-			goto disable;
-		}
+	ret = vip_gpio_reserve(&pdev->dev, config->reset_pin, 0,
+			       config->reset_name);
+	if (ret) {
+		vip_gpio_release(&pdev->dev, config->pwr_pin,
+				 config->pwr_name);
+		goto disable;
 	}
-	if (config->pwr_pin != -1) {
+
+	if (gpio_is_valid(config->pwr_pin)) {
 		/* Datasheet says 5ms between PWR and RST */
 		usleep_range(5000, 25000);
-		ret = gpio_direction_output(config->pwr_pin, 1);
+		gpio_direction_output(config->pwr_pin, 1);
 	}
 
-	if (config->reset_pin != -1) {
+	if (gpio_is_valid(config->reset_pin)) {
 		/* Datasheet says 5ms between PWR and RST */
 		usleep_range(5000, 25000);
-		ret = gpio_direction_output(config->reset_pin, 1);
+		gpio_direction_output(config->reset_pin, 1);
 	}
 	usleep_range(5000, 25000);
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-04-27 11:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-27 11:43 [PATCH 0/2] Use gpio_is_valid() Arvind Yadav
2018-04-27 11:44 ` [PATCH 1/2] [media] platform: " Arvind Yadav
2018-04-27 11:44 ` [PATCH 2/2] [media] sta2x11: Use gpio_is_valid() and remove unnecessary check Arvind Yadav

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).