Skip to content

Commit 61742a7

Browse files
tititiou36gregkh
authored andcommitted
devres: Slightly optimize alloc_dr()
If the gfp flag used for the memory allocation already has __GFP_ZERO, then there is no need to explicitly clear the "struct devres_node". It is already zeroed. This saves a few cycles when using devm_zalloc() and co. In the case of devres_alloc() (which calls __devres_alloc_node()), the compiler could remove the test and the memset() because it should be able to see that the __GFP_ZERO flag is set. So this would make the code both faster and smaller. Signed-off-by: Christophe JAILLET <[email protected]> Link: https://lore.kernel.org/r/d255bd871484e63cdd628e819f929e2df59afb02.1658352383.git.christophe.jaillet@wanadoo.fr Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6bb7ea3 commit 61742a7

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/base/devres.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ static __always_inline struct devres * alloc_dr(dr_release_t release,
117117
if (unlikely(!dr))
118118
return NULL;
119119

120-
memset(dr, 0, offsetof(struct devres, data));
120+
/* No need to clear memory twice */
121+
if (!(gfp & __GFP_ZERO))
122+
memset(dr, 0, offsetof(struct devres, data));
121123

122124
INIT_LIST_HEAD(&dr->node.entry);
123125
dr->node.release = release;

0 commit comments

Comments
 (0)