Re: [PATCH net-next 1/2] scripts/coccinelle: Find PTR_ERR() to %pe candidates

From: Simon Horman

Date: Fri Sep 19 2025 - 12:54:44 EST


On Thu, Sep 18, 2025 at 01:43:46PM +0300, Tariq Toukan wrote:
> From: Gal Pressman <gal@xxxxxxxxxx>
>
> Add a new Coccinelle script to identify places where PTR_ERR() is used
> in print functions and suggest using the %pe format specifier instead.
>
> For printing error pointers (i.e., a pointer for which IS_ERR() is true)
> %pe will print a symbolic error name (e.g,. -EINVAL), opposed to the raw
> errno (e.g,. -22) produced by PTR_ERR().
> It also makes the code cleaner by saving a redundant call to PTR_ERR().
>
> The script supports context, report, and org modes.
>
> Example transformation:
> printk("Error: %ld\n", PTR_ERR(ptr)); // Before
> printk("Error: %pe\n", ptr); // After
>
> Signed-off-by: Gal Pressman <gal@xxxxxxxxxx>
> Reviewed-by: Alexei Lazar <alazar@xxxxxxxxxx>
> Signed-off-by: Tariq Toukan <tariqt@xxxxxxxxxx>

Thanks, having this check seems very nice to me.

Reviewed-by: Simon Horman <horms@xxxxxxxxxx>