* [PATCH] ptp: chardev: Fix confusing cleanup.h syntax
@ 2025-12-08 2:08 Krzysztof Kozlowski
2025-12-08 19:06 ` Simon Horman
2025-12-09 7:51 ` Jakub Kicinski
0 siblings, 2 replies; 3+ messages in thread
From: Krzysztof Kozlowski @ 2025-12-08 2:08 UTC (permalink / raw)
To: Richard Cochran, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, netdev, linux-kernel
Cc: Krzysztof Kozlowski
Initializing automatic __free variables to NULL without need (e.g.
branches with different allocations), followed by actual allocation is
in contrary to explicit coding rules guiding cleanup.h:
"Given that the "__free(...) = NULL" pattern for variables defined at
the top of the function poses this potential interdependency problem the
recommendation is to always define and assign variables in one statement
and not group variable definitions at the top of the function when
__free() is used."
Code does not have a bug, but is less readable and uses discouraged
coding practice, so fix that by moving declaration to the place of
assignment.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
drivers/ptp/ptp_chardev.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c
index c61cf9edac48..2a52cc7bccd1 100644
--- a/drivers/ptp/ptp_chardev.c
+++ b/drivers/ptp/ptp_chardev.c
@@ -350,13 +350,13 @@ typedef int (*ptp_gettimex_fn)(struct ptp_clock_info *,
static long ptp_sys_offset_extended(struct ptp_clock *ptp, void __user *arg,
ptp_gettimex_fn gettimex_fn)
{
- struct ptp_sys_offset_extended *extoff __free(kfree) = NULL;
struct ptp_system_timestamp sts;
if (!gettimex_fn)
return -EOPNOTSUPP;
- extoff = memdup_user(arg, sizeof(*extoff));
+ struct ptp_sys_offset_extended *extoff __free(kfree) =
+ memdup_user(arg, sizeof(*extoff));
if (IS_ERR(extoff))
return PTR_ERR(extoff);
@@ -402,11 +402,11 @@ static long ptp_sys_offset_extended(struct ptp_clock *ptp, void __user *arg,
static long ptp_sys_offset(struct ptp_clock *ptp, void __user *arg)
{
- struct ptp_sys_offset *sysoff __free(kfree) = NULL;
struct ptp_clock_time *pct;
struct timespec64 ts;
- sysoff = memdup_user(arg, sizeof(*sysoff));
+ struct ptp_sys_offset *sysoff __free(kfree) =
+ memdup_user(arg, sizeof(*sysoff));
if (IS_ERR(sysoff))
return PTR_ERR(sysoff);
--
2.51.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] ptp: chardev: Fix confusing cleanup.h syntax
2025-12-08 2:08 [PATCH] ptp: chardev: Fix confusing cleanup.h syntax Krzysztof Kozlowski
@ 2025-12-08 19:06 ` Simon Horman
2025-12-09 7:51 ` Jakub Kicinski
1 sibling, 0 replies; 3+ messages in thread
From: Simon Horman @ 2025-12-08 19:06 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Richard Cochran, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, netdev, linux-kernel
On Mon, Dec 08, 2025 at 03:08:20AM +0100, Krzysztof Kozlowski wrote:
> Initializing automatic __free variables to NULL without need (e.g.
> branches with different allocations), followed by actual allocation is
> in contrary to explicit coding rules guiding cleanup.h:
>
> "Given that the "__free(...) = NULL" pattern for variables defined at
> the top of the function poses this potential interdependency problem the
> recommendation is to always define and assign variables in one statement
> and not group variable definitions at the top of the function when
> __free() is used."
>
> Code does not have a bug, but is less readable and uses discouraged
> coding practice, so fix that by moving declaration to the place of
> assignment.
>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Reviewed-by: Simon Horman <horms@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ptp: chardev: Fix confusing cleanup.h syntax
2025-12-08 2:08 [PATCH] ptp: chardev: Fix confusing cleanup.h syntax Krzysztof Kozlowski
2025-12-08 19:06 ` Simon Horman
@ 2025-12-09 7:51 ` Jakub Kicinski
1 sibling, 0 replies; 3+ messages in thread
From: Jakub Kicinski @ 2025-12-09 7:51 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Richard Cochran, Andrew Lunn, David S. Miller, Eric Dumazet,
Paolo Abeni, netdev, linux-kernel
On Mon, 8 Dec 2025 03:08:20 +0100 Krzysztof Kozlowski wrote:
> Code does not have a bug, but is less readable and uses discouraged
> coding practice, so fix that by moving declaration to the place of
> assignment.
I disagree, you're making this code look much worse.
Also, kfree() handles error pointers now?
--
pw-bot: reject
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-12-09 7:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-08 2:08 [PATCH] ptp: chardev: Fix confusing cleanup.h syntax Krzysztof Kozlowski
2025-12-08 19:06 ` Simon Horman
2025-12-09 7:51 ` Jakub Kicinski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).