diff mbox

pinctrl: add pinctrl_register_reason() to return proper error code

Message ID 1432899016-18155-1-git-send-email-yamada.masahiro@socionext.com
State New
Headers show

Commit Message

Masahiro Yamada May 29, 2015, 11:30 a.m. UTC
The pinctrl_register() just returns NULL on error, so the callers
can not know the exact reason of the failure.

Some of the pinctrl drivers return -EINVAL, some -ENODEV, and some
-ENOMEM on error of pinctrl_register() , although the error code
might be different from the actual cause of the error.

This new function, pinctrl_register_reason(), helps the drivers get
and return the appropriate error code.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Suggested-by: Arnd Bergmann <arnd@arndb.de>
---
If this patch is accepted, I can send a series to replace
the pinctrl_register() in each driver with pinctrl_register_reason().


 drivers/pinctrl/core.c          | 35 +++++++++++++++++++++++++----------
 include/linux/pinctrl/pinctrl.h |  2 ++
 2 files changed, 27 insertions(+), 10 deletions(-)

Comments

Soren Brinkmann May 29, 2015, 4:16 p.m. UTC | #1
On Fri, 2015-05-29 at 08:30PM +0900, Masahiro Yamada wrote:
> The pinctrl_register() just returns NULL on error, so the callers
> can not know the exact reason of the failure.
> 
> Some of the pinctrl drivers return -EINVAL, some -ENODEV, and some
> -ENOMEM on error of pinctrl_register() , although the error code
> might be different from the actual cause of the error.
> 
> This new function, pinctrl_register_reason(), helps the drivers get
> and return the appropriate error code.
> 
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> Suggested-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Sören Brinkmann <soren.brinkmann@xilinx.com>

	Sören
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Linus Walleij June 2, 2015, 12:56 p.m. UTC | #2
On Fri, May 29, 2015 at 1:30 PM, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:

> The pinctrl_register() just returns NULL on error, so the callers
> can not know the exact reason of the failure.
>
> Some of the pinctrl drivers return -EINVAL, some -ENODEV, and some
> -ENOMEM on error of pinctrl_register() , although the error code
> might be different from the actual cause of the error.
>
> This new function, pinctrl_register_reason(), helps the drivers get
> and return the appropriate error code.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> Suggested-by: Arnd Bergmann <arnd@arndb.de>

It should be named pinctrl_register_strict() or something.
"reason" is anyways wrong, should be "cause", but please
use _strict().

> If this patch is accepted, I can send a series to replace
> the pinctrl_register() in each driver with pinctrl_register_reason().

If it is replaced *everywhere* there is no point in keeping
a separate function. Then you should just do a big
patch changing all usage sites and the original function.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Masahiro Yamada June 2, 2015, 3:32 p.m. UTC | #3
Hi Linus,


2015-06-02 21:56 GMT+09:00 Linus Walleij <linus.walleij@linaro.org>:
> On Fri, May 29, 2015 at 1:30 PM, Masahiro Yamada
> <yamada.masahiro@socionext.com> wrote:
>
>> The pinctrl_register() just returns NULL on error, so the callers
>> can not know the exact reason of the failure.
>>
>> Some of the pinctrl drivers return -EINVAL, some -ENODEV, and some
>> -ENOMEM on error of pinctrl_register() , although the error code
>> might be different from the actual cause of the error.
>>
>> This new function, pinctrl_register_reason(), helps the drivers get
>> and return the appropriate error code.
>>
>> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
>> Suggested-by: Arnd Bergmann <arnd@arndb.de>
>
> It should be named pinctrl_register_strict() or something.
> "reason" is anyways wrong, should be "cause", but please
> use _strict().

OK, I will do it.


>> If this patch is accepted, I can send a series to replace
>> the pinctrl_register() in each driver with pinctrl_register_reason().
>
> If it is replaced *everywhere* there is no point in keeping
> a separate function. Then you should just do a big
> patch changing all usage sites and the original function.


If nobody is opposed to this, I can send a single big patch
replacing all the references.

In that case, we would not need _strict().

My concern is the sudden change of the function interface
will break drivers that are under development out of the source tree.
Linus Walleij June 8, 2015, 1:36 p.m. UTC | #4
On Tue, Jun 2, 2015 at 5:32 PM, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:

> If nobody is opposed to this, I can send a single big patch
> replacing all the references.
>
> In that case, we would not need _strict().

Yeah just do this.

> My concern is the sudden change of the function interface
> will break drivers that are under development out of the source tree.

Base the patch on my -devel branch so you cover all driver in
development. I will deal with any resulting mess.

Out of tree drivers we do not take into account, they should focus
their efforts on working upstream.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index f3cf3a8..39c284a 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -1692,26 +1692,27 @@  static int pinctrl_check_ops(struct pinctrl_dev *pctldev)
 }
 
 /**
- * pinctrl_register() - register a pin controller device
+ * pinctrl_register_reason() - register a pin controller device
  * @pctldesc: descriptor for this pin controller
  * @dev: parent device for this pin controller
  * @driver_data: private pin controller data for this pin controller
  */
-struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
-				    struct device *dev, void *driver_data)
+struct pinctrl_dev *pinctrl_register_reason(struct pinctrl_desc *pctldesc,
+					    struct device *dev,
+					    void *driver_data)
 {
 	struct pinctrl_dev *pctldev;
 	int ret;
 
 	if (!pctldesc)
-		return NULL;
+		return ERR_PTR(-EINVAL);
 	if (!pctldesc->name)
-		return NULL;
+		return ERR_PTR(-EINVAL);
 
 	pctldev = kzalloc(sizeof(*pctldev), GFP_KERNEL);
 	if (pctldev == NULL) {
 		dev_err(dev, "failed to alloc struct pinctrl_dev\n");
-		return NULL;
+		return ERR_PTR(-ENOMEM);
 	}
 
 	/* Initialize pin control device struct */
@@ -1724,20 +1725,23 @@  struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
 	mutex_init(&pctldev->mutex);
 
 	/* check core ops for sanity */
-	if (pinctrl_check_ops(pctldev)) {
+	ret = pinctrl_check_ops(pctldev);
+	if (ret) {
 		dev_err(dev, "pinctrl ops lacks necessary functions\n");
 		goto out_err;
 	}
 
 	/* If we're implementing pinmuxing, check the ops for sanity */
 	if (pctldesc->pmxops) {
-		if (pinmux_check_ops(pctldev))
+		ret = pinmux_check_ops(pctldev);
+		if (ret)
 			goto out_err;
 	}
 
 	/* If we're implementing pinconfig, check the ops for sanity */
 	if (pctldesc->confops) {
-		if (pinconf_check_ops(pctldev))
+		ret = pinconf_check_ops(pctldev);
+		if (ret)
 			goto out_err;
 	}
 
@@ -1783,7 +1787,18 @@  struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
 out_err:
 	mutex_destroy(&pctldev->mutex);
 	kfree(pctldev);
-	return NULL;
+	return ERR_PTR(ret);
+}
+EXPORT_SYMBOL_GPL(pinctrl_register_reason);
+
+struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
+				     struct device *dev, void *driver_data)
+{
+	struct pinctrl_dev *pctldev;
+
+	pctldev = pinctrl_register_reason(pctldesc, dev, driver_data);
+
+	return IS_ERR(pctldev) ? NULL : pctldev;
 }
 EXPORT_SYMBOL_GPL(pinctrl_register);
 
diff --git a/include/linux/pinctrl/pinctrl.h b/include/linux/pinctrl/pinctrl.h
index 9ba59fc..cb05866 100644
--- a/include/linux/pinctrl/pinctrl.h
+++ b/include/linux/pinctrl/pinctrl.h
@@ -143,6 +143,8 @@  struct pinctrl_desc {
 /* External interface to pin controller */
 extern struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
 				struct device *dev, void *driver_data);
+extern struct pinctrl_dev *pinctrl_register_reason(struct pinctrl_desc *pctldesc,
+				struct device *dev, void *driver_data);
 extern void pinctrl_unregister(struct pinctrl_dev *pctldev);
 extern bool pin_is_valid(struct pinctrl_dev *pctldev, int pin);
 extern void pinctrl_add_gpio_range(struct pinctrl_dev *pctldev,