[PATCH] mux: add missing mux_state_get

Peter Rosin posted 1 patch 4 years, 6 months ago
drivers/mux/core.c           | 41 ++++++++++++++++++++++++++----------
include/linux/mux/consumer.h |  1 +
2 files changed, 31 insertions(+), 11 deletions(-)
[PATCH] mux: add missing mux_state_get
Posted by Peter Rosin 4 years, 6 months ago
And implement devm_mux_state_get in terms of the new function.

Signed-off-by: Peter Rosin <peda@axentia.se>
---
 drivers/mux/core.c           | 41 ++++++++++++++++++++++++++----------
 include/linux/mux/consumer.h |  1 +
 2 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/drivers/mux/core.c b/drivers/mux/core.c
index 7d38e7c0c02e..90073ce01539 100644
--- a/drivers/mux/core.c
+++ b/drivers/mux/core.c
@@ -673,6 +673,33 @@ struct mux_control *devm_mux_control_get(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(devm_mux_control_get);
 
+/**
+ * mux_state_get() - Get the mux-state for a device.
+ * @dev: The device that needs a mux-state.
+ * @mux_name: The name identifying the mux-state.
+ *
+ * Return: A pointer to the mux-state, or an ERR_PTR with a negative errno.
+ */
+struct mux_state *mux_state_get(struct device *dev, const char *mux_name)
+{
+	struct mux_state *mstate;
+
+	mstate = kzalloc(sizeof(*mstate), GFP_KERNEL);
+	if (!mstate)
+		return ERR_PTR(-ENOMEM);
+
+	mstate->mux = mux_get(dev, mux_name, &mstate->state);
+	if (IS_ERR(mstate->mux)) {
+		int err = PTR_ERR(mstate->mux);
+
+		kfree(mstate);
+		return ERR_PTR(err);
+	}
+
+	return mstate;
+}
+EXPORT_SYMBOL_GPL(mux_state_get);
+
 /**
  * mux_state_put() - Put away the mux-state for good.
  * @mstate: The mux-state to put away.
@@ -705,25 +732,17 @@ struct mux_state *devm_mux_state_get(struct device *dev,
 				     const char *mux_name)
 {
 	struct mux_state **ptr, *mstate;
-	struct mux_control *mux_ctrl;
-	int state;
-
-	mstate = devm_kzalloc(dev, sizeof(struct mux_state), GFP_KERNEL);
-	if (!mstate)
-		return ERR_PTR(-ENOMEM);
 
 	ptr = devres_alloc(devm_mux_state_release, sizeof(*ptr), GFP_KERNEL);
 	if (!ptr)
 		return ERR_PTR(-ENOMEM);
 
-	mux_ctrl = mux_get(dev, mux_name, &state);
-	if (IS_ERR(mux_ctrl)) {
+	mstate = mux_state_get(dev, mux_name);
+	if (IS_ERR(mstate)) {
 		devres_free(ptr);
-		return (struct mux_state *)mux_ctrl;
+		return mstate;
 	}
 
-	mstate->mux = mux_ctrl;
-	mstate->state = state;
 	*ptr = mstate;
 	devres_add(dev, ptr);
 
diff --git a/include/linux/mux/consumer.h b/include/linux/mux/consumer.h
index babf2a744056..944678604549 100644
--- a/include/linux/mux/consumer.h
+++ b/include/linux/mux/consumer.h
@@ -54,6 +54,7 @@ int mux_control_deselect(struct mux_control *mux);
 int mux_state_deselect(struct mux_state *mstate);
 
 struct mux_control *mux_control_get(struct device *dev, const char *mux_name);
+struct mux_state *mux_state_get(struct device *dev, const char *mux_name);
 void mux_control_put(struct mux_control *mux);
 void mux_state_put(struct mux_state *mstate);
 
-- 
2.20.1


Re: [PATCH] mux: add missing mux_state_get
Posted by Aswath Govindraju 4 years, 6 months ago
On 19/12/21 12:07 am, Peter Rosin wrote:
> And implement devm_mux_state_get in terms of the new function.
> 
> Signed-off-by: Peter Rosin <peda@axentia.se>

Tested-by: Aswath Govindraju <a-govindraju@ti.com>

Thanks,
Aswath

> ---
>  drivers/mux/core.c           | 41 ++++++++++++++++++++++++++----------
>  include/linux/mux/consumer.h |  1 +
>  2 files changed, 31 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/mux/core.c b/drivers/mux/core.c
> index 7d38e7c0c02e..90073ce01539 100644
> --- a/drivers/mux/core.c
> +++ b/drivers/mux/core.c
> @@ -673,6 +673,33 @@ struct mux_control *devm_mux_control_get(struct device *dev,
>  }
>  EXPORT_SYMBOL_GPL(devm_mux_control_get);
>  
> +/**
> + * mux_state_get() - Get the mux-state for a device.
> + * @dev: The device that needs a mux-state.
> + * @mux_name: The name identifying the mux-state.
> + *
> + * Return: A pointer to the mux-state, or an ERR_PTR with a negative errno.
> + */
> +struct mux_state *mux_state_get(struct device *dev, const char *mux_name)
> +{
> +	struct mux_state *mstate;
> +
> +	mstate = kzalloc(sizeof(*mstate), GFP_KERNEL);
> +	if (!mstate)
> +		return ERR_PTR(-ENOMEM);
> +
> +	mstate->mux = mux_get(dev, mux_name, &mstate->state);
> +	if (IS_ERR(mstate->mux)) {
> +		int err = PTR_ERR(mstate->mux);
> +
> +		kfree(mstate);
> +		return ERR_PTR(err);
> +	}
> +
> +	return mstate;
> +}
> +EXPORT_SYMBOL_GPL(mux_state_get);
> +
>  /**
>   * mux_state_put() - Put away the mux-state for good.
>   * @mstate: The mux-state to put away.
> @@ -705,25 +732,17 @@ struct mux_state *devm_mux_state_get(struct device *dev,
>  				     const char *mux_name)
>  {
>  	struct mux_state **ptr, *mstate;
> -	struct mux_control *mux_ctrl;
> -	int state;
> -
> -	mstate = devm_kzalloc(dev, sizeof(struct mux_state), GFP_KERNEL);
> -	if (!mstate)
> -		return ERR_PTR(-ENOMEM);
>  
>  	ptr = devres_alloc(devm_mux_state_release, sizeof(*ptr), GFP_KERNEL);
>  	if (!ptr)
>  		return ERR_PTR(-ENOMEM);
>  
> -	mux_ctrl = mux_get(dev, mux_name, &state);
> -	if (IS_ERR(mux_ctrl)) {
> +	mstate = mux_state_get(dev, mux_name);
> +	if (IS_ERR(mstate)) {
>  		devres_free(ptr);
> -		return (struct mux_state *)mux_ctrl;
> +		return mstate;
>  	}
>  
> -	mstate->mux = mux_ctrl;
> -	mstate->state = state;
>  	*ptr = mstate;
>  	devres_add(dev, ptr);
>  
> diff --git a/include/linux/mux/consumer.h b/include/linux/mux/consumer.h
> index babf2a744056..944678604549 100644
> --- a/include/linux/mux/consumer.h
> +++ b/include/linux/mux/consumer.h
> @@ -54,6 +54,7 @@ int mux_control_deselect(struct mux_control *mux);
>  int mux_state_deselect(struct mux_state *mstate);
>  
>  struct mux_control *mux_control_get(struct device *dev, const char *mux_name);
> +struct mux_state *mux_state_get(struct device *dev, const char *mux_name);
>  void mux_control_put(struct mux_control *mux);
>  void mux_state_put(struct mux_state *mstate);
>  
> 

Re: [PATCH] mux: add missing mux_state_get
Posted by Peter Rosin 4 years, 6 months ago
On 2021-12-20 07:57, Aswath Govindraju wrote:
> 
> On 19/12/21 12:07 am, Peter Rosin wrote:
>> And implement devm_mux_state_get in terms of the new function.
>>
>> Signed-off-by: Peter Rosin <peda@axentia.se>
> 
> Tested-by: Aswath Govindraju <a-govindraju@ti.com>

Thanks!

I added the commit to the for-next branch. I will pass these mux
patches on to Greg when they have been in linux-next for a couple
of days for the bots to chew on. I can't be sure this will make
5.17-rc1 though, when we're already at 5.16-rc6 and the hollidays
are coming up.

We'll see.

Cheers,
Peter