diff mbox series

[v1] can: kvaser_usb: Simplify with dev_err_probe()

Message ID 20240830110651.519119-1-yanzhen@vivo.com (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series [v1] can: kvaser_usb: Simplify with dev_err_probe() | expand

Checks

Context Check Description
netdev/tree_selection success Series ignored based on subject

Commit Message

Yan Zhen Aug. 30, 2024, 11:06 a.m. UTC
dev_err_probe() is used to log an error message during the probe process 
of a device. 

It can simplify the error path and unify a message template.

Using this helper is totally fine even if err is known to never
be -EPROBE_DEFER.

The benefit compared to a normal dev_err() is the standardized format
of the error code, it being emitted symbolically and the fact that
the error code is returned which allows more compact error paths.

Signed-off-by: Yan Zhen <yanzhen@vivo.com>
---
 .../net/can/usb/kvaser_usb/kvaser_usb_core.c  | 42 +++++++------------
 1 file changed, 16 insertions(+), 26 deletions(-)

Comments

Alexander Lobakin Aug. 30, 2024, 12:50 p.m. UTC | #1
From: Yan Zhen <yanzhen@vivo.com>
Date: Fri, 30 Aug 2024 19:06:51 +0800

> dev_err_probe() is used to log an error message during the probe process 
> of a device. 
> 
> It can simplify the error path and unify a message template.
> 
> Using this helper is totally fine even if err is known to never
> be -EPROBE_DEFER.
> 
> The benefit compared to a normal dev_err() is the standardized format
> of the error code, it being emitted symbolically and the fact that
> the error code is returned which allows more compact error paths.
> 
> Signed-off-by: Yan Zhen <yanzhen@vivo.com>
> ---
>  .../net/can/usb/kvaser_usb/kvaser_usb_core.c  | 42 +++++++------------
>  1 file changed, 16 insertions(+), 26 deletions(-)
> 
> diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c
> index 35b4132b0639..bcf8d870af17 100644
> --- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c
> +++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c
> @@ -898,10 +898,8 @@ static int kvaser_usb_probe(struct usb_interface *intf,
>  	ops = driver_info->ops;
>  
>  	err = ops->dev_setup_endpoints(dev);
> -	if (err) {
> -		dev_err(&intf->dev, "Cannot get usb endpoint(s)");
> -		return err;
> -	}
> +	if (err)
> +		return dev_err_probe(&intf->dev, err, "Cannot get usb endpoint(s)");
>  
>  	dev->udev = interface_to_usbdev(intf);
>  
> @@ -912,26 +910,20 @@ static int kvaser_usb_probe(struct usb_interface *intf,
>  	dev->card_data.ctrlmode_supported = 0;
>  	dev->card_data.capabilities = 0;
>  	err = ops->dev_init_card(dev);
> -	if (err) {
> -		dev_err(&intf->dev,
> -			"Failed to initialize card, error %d\n", err);
> -		return err;
> -	}
> +	if (err)
> +		return dev_err_probe(&intf->dev, err,
> +					"Failed to initialize card\n");

The line wrap is wrong in all the places where you used it. It should be
aligned to the opening brace, like

		return dev_err_probe(&intf->dev, err,
				     "Failed ...)

Replace one tab with 5 spaces to fix that, here and in the whole patch.

>  
>  	err = ops->dev_get_software_info(dev);
> -	if (err) {
> -		dev_err(&intf->dev,
> -			"Cannot get software info, error %d\n", err);
> -		return err;

Thanks,
Olek
Marc Kleine-Budde Aug. 30, 2024, 2:18 p.m. UTC | #2
On 30.08.2024 14:50:44, Alexander Lobakin wrote:
> From: Yan Zhen <yanzhen@vivo.com>
> Date: Fri, 30 Aug 2024 19:06:51 +0800
> 
> > dev_err_probe() is used to log an error message during the probe process 
> > of a device. 
> > 
> > It can simplify the error path and unify a message template.
> > 
> > Using this helper is totally fine even if err is known to never
> > be -EPROBE_DEFER.
> > 
> > The benefit compared to a normal dev_err() is the standardized format
> > of the error code, it being emitted symbolically and the fact that
> > the error code is returned which allows more compact error paths.
> > 
> > Signed-off-by: Yan Zhen <yanzhen@vivo.com>
> > ---
> >  .../net/can/usb/kvaser_usb/kvaser_usb_core.c  | 42 +++++++------------
> >  1 file changed, 16 insertions(+), 26 deletions(-)
> > 
> > diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c
> > index 35b4132b0639..bcf8d870af17 100644
> > --- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c
> > +++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c
> > @@ -898,10 +898,8 @@ static int kvaser_usb_probe(struct usb_interface *intf,
> >  	ops = driver_info->ops;
> >  
> >  	err = ops->dev_setup_endpoints(dev);
> > -	if (err) {
> > -		dev_err(&intf->dev, "Cannot get usb endpoint(s)");
> > -		return err;
> > -	}
> > +	if (err)
> > +		return dev_err_probe(&intf->dev, err, "Cannot get usb endpoint(s)");
> >  
> >  	dev->udev = interface_to_usbdev(intf);
> >  
> > @@ -912,26 +910,20 @@ static int kvaser_usb_probe(struct usb_interface *intf,
> >  	dev->card_data.ctrlmode_supported = 0;
> >  	dev->card_data.capabilities = 0;
> >  	err = ops->dev_init_card(dev);
> > -	if (err) {
> > -		dev_err(&intf->dev,
> > -			"Failed to initialize card, error %d\n", err);
> > -		return err;
> > -	}
> > +	if (err)
> > +		return dev_err_probe(&intf->dev, err,
> > +					"Failed to initialize card\n");
> 
> The line wrap is wrong in all the places where you used it. It should be
> aligned to the opening brace, like
> 
> 		return dev_err_probe(&intf->dev, err,
> 				     "Failed ...)
> 
> Replace one tab with 5 spaces to fix that, here and in the whole patch.

Fixed while applying.

Thanks,
Marc
diff mbox series

Patch

diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c
index 35b4132b0639..bcf8d870af17 100644
--- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c
+++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c
@@ -898,10 +898,8 @@  static int kvaser_usb_probe(struct usb_interface *intf,
 	ops = driver_info->ops;
 
 	err = ops->dev_setup_endpoints(dev);
-	if (err) {
-		dev_err(&intf->dev, "Cannot get usb endpoint(s)");
-		return err;
-	}
+	if (err)
+		return dev_err_probe(&intf->dev, err, "Cannot get usb endpoint(s)");
 
 	dev->udev = interface_to_usbdev(intf);
 
@@ -912,26 +910,20 @@  static int kvaser_usb_probe(struct usb_interface *intf,
 	dev->card_data.ctrlmode_supported = 0;
 	dev->card_data.capabilities = 0;
 	err = ops->dev_init_card(dev);
-	if (err) {
-		dev_err(&intf->dev,
-			"Failed to initialize card, error %d\n", err);
-		return err;
-	}
+	if (err)
+		return dev_err_probe(&intf->dev, err,
+					"Failed to initialize card\n");
 
 	err = ops->dev_get_software_info(dev);
-	if (err) {
-		dev_err(&intf->dev,
-			"Cannot get software info, error %d\n", err);
-		return err;
-	}
+	if (err)
+		return dev_err_probe(&intf->dev, err,
+					"Cannot get software info\n");
 
 	if (ops->dev_get_software_details) {
 		err = ops->dev_get_software_details(dev);
-		if (err) {
-			dev_err(&intf->dev,
-				"Cannot get software details, error %d\n", err);
-			return err;
-		}
+		if (err)
+			return dev_err_probe(&intf->dev, err,
+						"Cannot get software details\n");
 	}
 
 	if (WARN_ON(!dev->cfg))
@@ -945,18 +937,16 @@  static int kvaser_usb_probe(struct usb_interface *intf,
 	dev_dbg(&intf->dev, "Max outstanding tx = %d URBs\n", dev->max_tx_urbs);
 
 	err = ops->dev_get_card_info(dev);
-	if (err) {
-		dev_err(&intf->dev, "Cannot get card info, error %d\n", err);
-		return err;
-	}
+	if (err)
+		return dev_err_probe(&intf->dev, err,
+					"Cannot get card info\n");
 
 	if (ops->dev_get_capabilities) {
 		err = ops->dev_get_capabilities(dev);
 		if (err) {
-			dev_err(&intf->dev,
-				"Cannot get capabilities, error %d\n", err);
 			kvaser_usb_remove_interfaces(dev);
-			return err;
+			return dev_err_probe(&intf->dev, err,
+						"Cannot get capabilities\n");
 		}
 	}