diff mbox series

[2/2,next] mm: memcontrol: Use the preferred form for passing the size of a structure type

Message ID 773e013ff2f07fe2a0b47153f14dea054c0c04f1.1596214831.git.gustavoars@kernel.org (mailing list archive)
State New, archived
Headers show
Series Use flexible_array_size() helper in memcpy() | expand

Commit Message

Gustavo A. R. Silva July 31, 2020, 5:13 p.m. UTC
Use the preferred form for passing the size of a structure type. The
alternative form where the structure type is spelled out hurts
readability and introduces an opportunity for a bug when the object
type is changed but the corresponding object identifier to which the
sizeof operator is applied is not.

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 mm/memcontrol.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Michal Hocko Aug. 4, 2020, 1:25 p.m. UTC | #1
On Fri 31-07-20 12:13:14, Gustavo A. R. Silva wrote:
> Use the preferred form for passing the size of a structure type. The
> alternative form where the structure type is spelled out hurts
> readability and introduces an opportunity for a bug when the object
> type is changed but the corresponding object identifier to which the
> sizeof operator is applied is not.
> 
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  mm/memcontrol.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index bd7f972ceea4..bd0f56785841 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -4255,7 +4255,7 @@ static int __mem_cgroup_usage_register_event(struct mem_cgroup *memcg,
>  	new->entries[size - 1].threshold = threshold;
>  
>  	/* Sort thresholds. Registering of new threshold isn't time-critical */
> -	sort(new->entries, size, sizeof(struct mem_cgroup_threshold),
> +	sort(new->entries, size, sizeof(*new->entries),
>  			compare_thresholds, NULL);
>  
>  	/* Find current threshold */
> -- 
> 2.27.0
diff mbox series

Patch

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index bd7f972ceea4..bd0f56785841 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4255,7 +4255,7 @@  static int __mem_cgroup_usage_register_event(struct mem_cgroup *memcg,
 	new->entries[size - 1].threshold = threshold;
 
 	/* Sort thresholds. Registering of new threshold isn't time-critical */
-	sort(new->entries, size, sizeof(struct mem_cgroup_threshold),
+	sort(new->entries, size, sizeof(*new->entries),
 			compare_thresholds, NULL);
 
 	/* Find current threshold */