Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7254147rwb; Wed, 23 Nov 2022 04:23:33 -0800 (PST) X-Google-Smtp-Source: AA0mqf42unw2vs1lw9kDdWyqrbvqs3NqfdnYDmCUJN8sNkLFO9rs7sGdYAeAAybcasDYdTM31wHO X-Received: by 2002:a63:4424:0:b0:477:96e2:9065 with SMTP id r36-20020a634424000000b0047796e29065mr8024643pga.533.1669206213382; Wed, 23 Nov 2022 04:23:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669206213; cv=none; d=google.com; s=arc-20160816; b=kJzuznxXIg3ssjbfbT7MUhm4lQzgtDBD+OpAiK0ZlmtM77P1kfiyV4bV4I7GsQUIXC 0ZOCEAn5Xswc0UYvxDEcteHwtAfbMwE9RYy7JJwnTKxQvGkavP4ZvwcNz+3/cTOaXsc5 jCGLTMLYRmZvG3AXyfFuuHxC/TgZRAinG9dIYrrn3vZYTvCSKOuv/F+x5TItEPXzHcRF sO2ciwhpTaJtiov4NqtvZvBuNrjGLBIZBX+CTNdabI0MjKYcrnPk2TvMwL7RUmGuAYp2 jOlvND+6OIX/9qcmW4gdBOYJNBYcZNOB0sAFnzJYscpwnqQAHEcrnxLFJyzttSOQFow3 E+jA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=hcR8ovYNo2My0WUKcVnNmYC5cYpEMC0rr3gdSJ74NfU=; b=BKbD3qrVnQR+sk2s4hqXVpWfHaHVVRXHrbNphZZCZn9swWLBF729WswNwNhSEH+O+z YxeshwHzuw/DZ/CEzBNO+XSV9cwdnETnDkmJzy/qNuWavy/9l4yjIfEFyd+uSIPbHumL FSR3Sa3G/t/JFivQrIGF0HvTwCB8ritj1HPgsR9Fk8wwbD2Id2a+pWY0wqRWwvZ6oRIE lVGUctmlihgVqy6LC8o/N346HJ/wCMhpWabWQT27W97ODk4klpks3pY2sfi8FXLyUedl Yu8DP5YXABjH4fsa+cAaoGPzM1fY8BWMAQr3NRz+Ih+Q2VlRpwNw6olwgijPC3EVa+NV Kv9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZrlPHAS+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b9-20020a170902e94900b00186881688f9si16313702pll.276.2022.11.23.04.23.19; Wed, 23 Nov 2022 04:23:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZrlPHAS+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237125AbiKWMAs (ORCPT + 89 others); Wed, 23 Nov 2022 07:00:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237133AbiKWMAp (ORCPT ); Wed, 23 Nov 2022 07:00:45 -0500 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36249624A for ; Wed, 23 Nov 2022 04:00:44 -0800 (PST) Received: by mail-lf1-x136.google.com with SMTP id s8so27820396lfc.8 for ; Wed, 23 Nov 2022 04:00:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=hcR8ovYNo2My0WUKcVnNmYC5cYpEMC0rr3gdSJ74NfU=; b=ZrlPHAS+WGiK3Lav2tjX9E3L3EQhNwAGul34uyaC6bhMi4CQY5elSYO++LxtQ+rIG7 pynaS8fphG+u0aowuVnGAGSO308yaigyNIPmgo2h9itDgHFQKi03T7NGZl+96WAr7+k1 OKf6GBFSb/8U0NObV+mVI5sikProfgzcwhqJoiErqM490fCODGRBD2biWQLeX63LAIT6 9gHBFjNOMOc5CaeR8dEZKz+2i9v0z5qpZpEep3MVS+ZoeSAmAo3SN1wnPVS6uKXFPs71 fqYOZt/GYlz08sOgbf1t2FvLTMExnQPPTa0b6TK1jk+wTPp1uNOznGI4Yk9le4LNWiDs vwWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=hcR8ovYNo2My0WUKcVnNmYC5cYpEMC0rr3gdSJ74NfU=; b=TLCDroC83hHX9dRrRPu09a9hfEkH9w2YnfqNWGW9hvrYBybRbbpMXNCqiTNDSHuWIp Yq0iD/5phcZk3sK7dSjteKQ6EKSEABaPCF6gee1WC11ESBKlES9pikfRcP5nbJ3y2gYU hIXDPY2qRDzLvyYSFG5r+FZz/DyszAYEEyKm+fsGBQmGnJK/093HwVmRRah4DtYcMD41 1EseJA3FLGnJ4127NDJjHBraPoVvFe5Jkss1QwesU3PotorYvnk5G/nHsP//4HHtvdgy 2zatYOsvjp+EH4nl4l5MmX1BgiiAEa6bkarVIwUqY9CsPHuP6XpusE/CtiplWcvroJdt kshg== X-Gm-Message-State: ANoB5pl4U1IWzBbCfTUPPSNspUxYc7EXIUS36MZcdIxj/SRL1wzbLUPq jPLhO4c/UCW3SGPKdy0wJEEBOODMDM4= X-Received: by 2002:a05:6512:68b:b0:4a8:d2b7:ed5c with SMTP id t11-20020a056512068b00b004a8d2b7ed5cmr10789411lfe.434.1669204842474; Wed, 23 Nov 2022 04:00:42 -0800 (PST) Received: from fedora ([213.255.186.46]) by smtp.gmail.com with ESMTPSA id o7-20020ac25e27000000b004b48c977d8dsm2892067lfg.125.2022.11.23.04.00.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 04:00:41 -0800 (PST) Date: Wed, 23 Nov 2022 14:00:38 +0200 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Matti Vaittinen , Liam Girdwood , Mark Brown , linux-kernel@vger.kernel.org Subject: [PATCH 3/3] regulator: bd718x7: Use dev_err_probe() Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="+iqplJKpcdzleyKU" Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --+iqplJKpcdzleyKU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable The dev_err_probe() has (at least) following benefits over dev_err() when printing an error print for a failed function call at a device driver probe: - Omit error level print if error is 'EPRBE_DEFER' - Standardized print format for returned error - return the error value allowing shortening calls like: if (ret) { dev_err(...); return ret; } to if (ret) return dev_err_probe(...); Convert the ROHM BD718x7 regulator driver to use the dev_err_probe() when returned error is not hard-coded constant. NOTE: This commit also changes the error handling path to return immediately =66rom a spot where the error is spotted instead of using a single point of exit. Signed-off-by: Matti Vaittinen --- For many years I have preferred a single point of exit in a function when managing it does not require any big tricks. In my experience a single point of exit makes resource-leaking and lock releasing much less error prone. Eg, consider mistakes like: =2E.. mutex_lock(&mtx) =2E.. if (err) return err; =2E.. mutex_unlock(&mtx); return 0; Vs. =2E.. mutex_lock(&mtx) =2E.. if (err) goto err_out; =2E.. err_out: mutex_unlock(&mtx); return err; I still think a single point of exit is often a good idea. However, I am slowly adapting to thought that the single point of exit does not really play a big role in bd718x7 regulator probe and using dev_err_probe() allows us to avoid the extra {} after condition... So, maybe it indeed is a time for me to ditch the goto here. Please, let me know if you think othervice :) --- drivers/regulator/bd718x7-regulator.c | 51 ++++++++++----------------- 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/drivers/regulator/bd718x7-regulator.c b/drivers/regulator/bd71= 8x7-regulator.c index d161b0026f33..894fab0d53d0 100644 --- a/drivers/regulator/bd718x7-regulator.c +++ b/drivers/regulator/bd718x7-regulator.c @@ -1706,20 +1706,17 @@ static int bd718xx_probe(struct platform_device *pd= ev) break; default: dev_err(&pdev->dev, "Unsupported chip type\n"); - err =3D -EINVAL; - goto err; + return -EINVAL; } =20 /* Register LOCK release */ err =3D regmap_update_bits(regmap, BD718XX_REG_REGLOCK, (REGLOCK_PWRSEQ | REGLOCK_VREG), 0); - if (err) { - dev_err(&pdev->dev, "Failed to unlock PMIC (%d)\n", err); - goto err; - } else { - dev_dbg(&pdev->dev, "Unlocked lock register 0x%x\n", - BD718XX_REG_REGLOCK); - } + if (err) + return dev_err_probe(&pdev->dev, err, "Failed to unlock PMIC\n"); + + dev_dbg(&pdev->dev, "Unlocked lock register 0x%x\n", + BD718XX_REG_REGLOCK); =20 use_snvs =3D of_property_read_bool(pdev->dev.parent->of_node, "rohm,reset-snvs-powered"); @@ -1736,13 +1733,11 @@ static int bd718xx_probe(struct platform_device *pd= ev) BD718XX_WDOG_POWEROFF_MASK | BD718XX_KEY_L_POWEROFF_MASK, BD718XX_POWOFF_TO_RDY); - if (err) { - dev_err(&pdev->dev, "Failed to change reset target\n"); - goto err; - } else { - dev_dbg(&pdev->dev, - "Changed all resets from SVNS to READY\n"); - } + if (err) + return dev_err_probe(&pdev->dev, err, + "Failed to change reset target\n"); + + dev_dbg(&pdev->dev, "Changed all resets from SVNS to READY\n"); } =20 config.dev =3D pdev->dev.parent; @@ -1778,13 +1773,10 @@ static int bd718xx_probe(struct platform_device *pd= ev) desc->ops =3D swops[i]; =20 rdev =3D devm_regulator_register(&pdev->dev, desc, &config); - if (IS_ERR(rdev)) { - dev_err(&pdev->dev, - "failed to register %s regulator\n", - desc->name); - err =3D PTR_ERR(rdev); - goto err; - } + if (IS_ERR(rdev)) + return dev_err_probe(&pdev->dev, PTR_ERR(rdev), + "failed to register %s regulator\n", + desc->name); =20 /* * Regulator register gets the regulator constraints and @@ -1807,28 +1799,23 @@ static int bd718xx_probe(struct platform_device *pd= ev) !rdev->constraints->boot_on)) { err =3D regmap_update_bits(regmap, r->init.reg, r->init.mask, r->init.val); - if (err) { - dev_err(&pdev->dev, + if (err) + return dev_err_probe(&pdev->dev, err, "Failed to take control for (%s)\n", desc->name); - goto err; - } } for (j =3D 0; j < r->additional_init_amnt; j++) { err =3D regmap_update_bits(regmap, r->additional_inits[j].reg, r->additional_inits[j].mask, r->additional_inits[j].val); - if (err) { - dev_err(&pdev->dev, + if (err) + return dev_err_probe(&pdev->dev, err, "Buck (%s) initialization failed\n", desc->name); - goto err; - } } } =20 -err: return err; } =20 --=20 2.38.1 --=20 Matti Vaittinen, Linux device drivers ROHM Semiconductors, Finland SWDC Kiviharjunlenkki 1E 90220 OULU FINLAND ~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~ Simon says - in Latin please. ~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~ Thanks to Simon Glass for the translation =3D]=20 --+iqplJKpcdzleyKU Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEIx+f8wZb28fLKEhTeFA3/03aocUFAmN+C2YACgkQeFA3/03a ocUWRgf/fEgNu7YYaMh5NmKk50Btq9kWI28dfnEKIa8PQAhJ6IePYvwfwAP7p4Ke mr+XktaBV0CQi2e4yENTKuZMk1XKGY4mHuO7rdMNYrbR6EqWmia0ijZwai4FAi9Q 2Iga1IYdAHtuU5RX4yuFr8E8r7ZzppxBU4RjslIMt7MB8/kl/xqSdJWaSVLs0oLb CQ4bftM8X5LHsRoQ3swbJIRQVBt3FsZEokDARIgaUSogykSd8SoOCY9/usThzH6Q 004f5ugNtR5XwwYyXvkDOJo4DRgcA8i3yrTZ/YpVLJMZwEBVkagnlZ18NnZqXpn6 tjyl8BWn58Gthij524kFUh71QlhkaA== =47Ei -----END PGP SIGNATURE----- --+iqplJKpcdzleyKU--