mux: Fix struct mux_state kernel-doc comment
[linux-2.6-microblaze.git] / drivers / mux / core.c
index 931fa8b..49bedbe 100644 (file)
@@ -33,7 +33,7 @@
  * struct mux_state -  Represents a mux controller state specific to a given
  *                     consumer.
  * @mux:               Pointer to a mux controller.
- * @state              State of the mux to be selected.
+ * @state:             State of the mux to be selected.
  *
  * This structure is specific to the consumer that acquires it and has
  * information specific to that consumer.
@@ -416,7 +416,7 @@ EXPORT_SYMBOL_GPL(mux_state_select_delay);
  * @delay_us: The time to delay (in microseconds) if the mux state is changed.
  *
  * On successfully selecting the mux-control state, it will be locked until
- * mux_control_deselect() called.
+ * mux_control_deselect() is called.
  *
  * Therefore, make sure to call mux_control_deselect() when the operation is
  * complete and the mux-control is free for others to use, but do not call
@@ -673,6 +673,32 @@ 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.
+ */
+static 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;
+}
+
 /*
  * mux_state_put() - Put away the mux-state for good.
  * @mstate: The mux-state to put away.
@@ -704,25 +730,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);