From nobody Mon Apr 6 03:12:24 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA574ECAAD3 for ; Sun, 11 Sep 2022 13:15:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230167AbiIKNPo (ORCPT ); Sun, 11 Sep 2022 09:15:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229895AbiIKNPj (ORCPT ); Sun, 11 Sep 2022 09:15:39 -0400 Received: from smtp.smtpout.orange.fr (smtp08.smtpout.orange.fr [80.12.242.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7284913F27 for ; Sun, 11 Sep 2022 06:15:37 -0700 (PDT) Received: from pop-os.home ([90.11.190.129]) by smtp.orange.fr with ESMTPA id XMoAo3G0KjJi0XMoBoWog3; Sun, 11 Sep 2022 15:15:36 +0200 X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 11 Sep 2022 15:15:36 +0200 X-ME-IP: 90.11.190.129 From: Christophe JAILLET To: Andy Whitcroft , Joe Perches , Dwaipayan Ray , Lukas Bulwahn Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [RFC PATCH] checkpatch: Check check for places where dev_err_probe() would likely be better than dev_err() Date: Sun, 11 Sep 2022 15:15:33 +0200 Message-Id: <3cdc2e776dea77b07c75694ba1410bd21e8ed749.1662902045.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Some functions are known to potentially return -EPROBE_DEFER. In such a case, it is likely that dev_err_probe() is a better choice than err_err(). dev_err_probe(): - is usually less verbose - generates smaller .o files - handles -EPROBE_DEFER so that logs are not spammed - automatically log the error code in a human readable way Signed-off-by: Christophe JAILLET Acked-by: Linus Walleij --- This patch is only a PoC to see if there is some interest in such a new check. The hard coded '5 lines of context' has been chosen because a typical pattern is: clk =3D devm_clk_get(dev, "clk_lcd"); if (IS_ERR(clk) { dev_err(dev, "Error meesage\n"); return PTR_ERR(clk); } --- scripts/checkpatch.pl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 2737e4ced574..88365749ed2e 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2625,6 +2625,9 @@ sub process { my $last_blank_line =3D 0; my $last_coalesced_string_linenr =3D -1; =20 + my $last_function_that_return_defer =3D ""; + my $last_function_that_return_defer_linenr =3D 0; + our @report =3D (); our $cnt_lines =3D 0; our $cnt_error =3D 0; @@ -7459,6 +7462,17 @@ sub process { WARN("DUPLICATED_SYSCTL_CONST", "duplicated sysctl range checking value '$1', consider using the share= d one in include/linux/sysctl.h\n" . $herecurr); } + +# check for places where dev_err_probe() would likely be better than dev_e= rr() + if ($line =3D~ /((?:devm_)?clk_get)s*\(/) { + $last_function_that_return_defer =3D $1; + $last_function_that_return_defer_linenr =3D $linenr; + } + if ($last_function_that_return_defer_linenr >=3D ($linenr - 5) && + $line =3D~ /dev_err[^_]/) { + WARN("LIKELY_DEV_ERR_PROBE", + "dev_err_probe() is likely a better choice than err_err() after a " . = $last_function_that_return_defer . "() call\n" . $herecurr); + } } =20 # If we have no input at all, then there is nothing to report on --=20 2.34.1