diff mbox series

[v1] usb: typec: Return size of buffer if pd_set operation succeeds

Message ID 20240319074309.3306579-1-kyletso@google.com (mailing list archive)
State Accepted
Commit 53f5094fdf5deacd99b8655df692e9278506724d
Headers show
Series [v1] usb: typec: Return size of buffer if pd_set operation succeeds | expand

Commit Message

Kyle Tso March 19, 2024, 7:43 a.m. UTC
The attribute writing should return the number of bytes used from the
buffer on success.

Fixes: a7cff92f0635 ("usb: typec: USB Power Delivery helpers for ports and partners")
Cc: stable@vger.kernel.org
Signed-off-by: Kyle Tso <kyletso@google.com>
---
 drivers/usb/typec/class.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Guenter Roeck March 19, 2024, 1:58 p.m. UTC | #1
On 3/19/24 00:43, Kyle Tso wrote:
> The attribute writing should return the number of bytes used from the
> buffer on success.
> 
> Fixes: a7cff92f0635 ("usb: typec: USB Power Delivery helpers for ports and partners")
> Cc: stable@vger.kernel.org
> Signed-off-by: Kyle Tso <kyletso@google.com>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
>   drivers/usb/typec/class.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index 389c7f0b8d93..9610e647a8d4 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -1310,6 +1310,7 @@ static ssize_t select_usb_power_delivery_store(struct device *dev,
>   {
>   	struct typec_port *port = to_typec_port(dev);
>   	struct usb_power_delivery *pd;
> +	int ret;
>   
>   	if (!port->ops || !port->ops->pd_set)
>   		return -EOPNOTSUPP;
> @@ -1318,7 +1319,11 @@ static ssize_t select_usb_power_delivery_store(struct device *dev,
>   	if (!pd)
>   		return -EINVAL;
>   
> -	return port->ops->pd_set(port, pd);
> +	ret = port->ops->pd_set(port, pd);
> +	if (ret)
> +		return ret;
> +
> +	return size;
>   }
>   
>   static ssize_t select_usb_power_delivery_show(struct device *dev,
Heikki Krogerus March 22, 2024, 9:47 a.m. UTC | #2
On Tue, Mar 19, 2024 at 03:43:09PM +0800, Kyle Tso wrote:
> The attribute writing should return the number of bytes used from the
> buffer on success.
> 
> Fixes: a7cff92f0635 ("usb: typec: USB Power Delivery helpers for ports and partners")
> Cc: stable@vger.kernel.org
> Signed-off-by: Kyle Tso <kyletso@google.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/typec/class.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index 389c7f0b8d93..9610e647a8d4 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -1310,6 +1310,7 @@ static ssize_t select_usb_power_delivery_store(struct device *dev,
>  {
>  	struct typec_port *port = to_typec_port(dev);
>  	struct usb_power_delivery *pd;
> +	int ret;
>  
>  	if (!port->ops || !port->ops->pd_set)
>  		return -EOPNOTSUPP;
> @@ -1318,7 +1319,11 @@ static ssize_t select_usb_power_delivery_store(struct device *dev,
>  	if (!pd)
>  		return -EINVAL;
>  
> -	return port->ops->pd_set(port, pd);
> +	ret = port->ops->pd_set(port, pd);
> +	if (ret)
> +		return ret;
> +
> +	return size;
>  }
>  
>  static ssize_t select_usb_power_delivery_show(struct device *dev,
> -- 
> 2.44.0.291.gc1ea87d7ee-goog
diff mbox series

Patch

diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index 389c7f0b8d93..9610e647a8d4 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -1310,6 +1310,7 @@  static ssize_t select_usb_power_delivery_store(struct device *dev,
 {
 	struct typec_port *port = to_typec_port(dev);
 	struct usb_power_delivery *pd;
+	int ret;
 
 	if (!port->ops || !port->ops->pd_set)
 		return -EOPNOTSUPP;
@@ -1318,7 +1319,11 @@  static ssize_t select_usb_power_delivery_store(struct device *dev,
 	if (!pd)
 		return -EINVAL;
 
-	return port->ops->pd_set(port, pd);
+	ret = port->ops->pd_set(port, pd);
+	if (ret)
+		return ret;
+
+	return size;
 }
 
 static ssize_t select_usb_power_delivery_show(struct device *dev,