[PATCH v1] misc: genwqe: Simplify with dev_err_probe()

Shen Lichuan posted 1 patch 1 year, 5 months ago
drivers/misc/genwqe/card_base.c | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
[PATCH v1] misc: genwqe: Simplify with dev_err_probe()
Posted by Shen Lichuan 1 year, 5 months ago
Use dev_err_probe() to 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: Shen Lichuan <shenlichuan@vivo.com>
---
 drivers/misc/genwqe/card_base.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/drivers/misc/genwqe/card_base.c b/drivers/misc/genwqe/card_base.c
index 224a7e97cbea..4e882bff7ee5 100644
--- a/drivers/misc/genwqe/card_base.c
+++ b/drivers/misc/genwqe/card_base.c
@@ -1185,35 +1185,32 @@ static int genwqe_probe(struct pci_dev *pci_dev,
 	genwqe_init_crc32();
 
 	cd = genwqe_dev_alloc();
-	if (IS_ERR(cd)) {
-		dev_err(&pci_dev->dev, "err: could not alloc mem (err=%d)!\n",
-			(int)PTR_ERR(cd));
-		return PTR_ERR(cd);
-	}
+	if (IS_ERR(cd))
+		return dev_err_probe(&pci_dev->dev, PTR_ERR(cd),
+				     "could not alloc mem\n");
 
 	dev_set_drvdata(&pci_dev->dev, cd);
 	cd->pci_dev = pci_dev;
 
 	err = genwqe_pci_setup(cd);
 	if (err < 0) {
-		dev_err(&pci_dev->dev,
-			"err: problems with PCI setup (err=%d)\n", err);
+		dev_err_probe(&pci_dev->dev, err,
+			      "problems with PCI setup\n");
 		goto out_free_dev;
 	}
 
 	err = genwqe_start(cd);
 	if (err < 0) {
-		dev_err(&pci_dev->dev,
-			"err: cannot start card services! (err=%d)\n", err);
+		dev_err_probe(&pci_dev->dev, err,
+			      "cannot start card services!\n");
 		goto out_pci_remove;
 	}
 
 	if (genwqe_is_privileged(cd)) {
 		err = genwqe_health_check_start(cd);
 		if (err < 0) {
-			dev_err(&pci_dev->dev,
-				"err: cannot start health checking! (err=%d)\n",
-				err);
+			dev_err_probe(&pci_dev->dev, err,
+				      "cannot start health checking!\n");
 			goto out_stop_services;
 		}
 	}
-- 
2.17.1
Re: [PATCH v1] misc: genwqe: Simplify with dev_err_probe()
Posted by Krzysztof Kozlowski 1 year, 5 months ago
On 30/08/2024 10:38, Shen Lichuan wrote:
> Use dev_err_probe() to 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: Shen Lichuan <shenlichuan@vivo.com>
> ---
>  drivers/misc/genwqe/card_base.c | 21 +++++++++------------
>  1 file changed, 9 insertions(+), 12 deletions(-)
> 

Since ~2 weeks there is tremendous amount of trivial patches coming from
vivo.com. I identified at least 6 buggy, where the contributor did not
understand the code. Not sure about intention, but I advise extra
carefulness when dealing with these "trivial" improvements (because we
tend to apply things which look trivial).


Best regards,
Krzysztof