diff mbox series

[RFC] mm/damon/sysfs: add __counted_by() annotation

Message ID 20230825020441.65431-1-sj@kernel.org (mailing list archive)
State New
Headers show
Series [RFC] mm/damon/sysfs: add __counted_by() annotation | expand

Commit Message

SeongJae Park Aug. 25, 2023, 2:04 a.m. UTC
Commit dd06e72e68bc ("Compiler Attributes: Add __counted_by macro")
added __counted_by() annotation.  The underlying attribute for the
feature is still under development, but adopting it can improve the
readability of the code.  Apply it to four dynamic arrays in DAMON sysfs
code.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/sysfs.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Kees Cook Aug. 25, 2023, 9:32 p.m. UTC | #1
On Fri, Aug 25, 2023 at 02:04:41AM +0000, SeongJae Park wrote:
> Commit dd06e72e68bc ("Compiler Attributes: Add __counted_by macro")
> added __counted_by() annotation.  The underlying attribute for the
> feature is still under development, but adopting it can improve the
> readability of the code.  Apply it to four dynamic arrays in DAMON sysfs
> code.
> 
> Signed-off-by: SeongJae Park <sj@kernel.org>
> ---
>  mm/damon/sysfs.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
> index 808a8efe0523..36a176f38726 100644
> --- a/mm/damon/sysfs.c
> +++ b/mm/damon/sysfs.c
> @@ -93,7 +93,7 @@ static const struct kobj_type damon_sysfs_region_ktype = {
> 
>  struct damon_sysfs_regions {
>  	struct kobject kobj;
> -	struct damon_sysfs_region **regions_arr;
> +	struct damon_sysfs_region **regions_arr __counted_by(nr);
>  	int nr;
>  };

Unfortunately this isn't supported yet for non-flexible-array-members:

mm/damon/sysfs.c:96:14: error: 'counted_by' attribute may not be specified for a non-array field
   96 |         struct damon_sysfs_region **regions_arr __counted_by(nr);
      |                                     ^~~~~

We'll have to wait a bit before we can add this patch. Thank you for
getting it ready, though! This support is next in line. :)

The FAM support is likely ready to land, though[1]. I just tested it
today.

-Kees

[1] https://gcc.gnu.org/pipermail/gcc-patches/2023-August/628459.html
SeongJae Park Aug. 26, 2023, 12:54 a.m. UTC | #2
Hi Kees,

On Fri, 25 Aug 2023 14:32:34 -0700 Kees Cook <keescook@chromium.org> wrote:

> On Fri, Aug 25, 2023 at 02:04:41AM +0000, SeongJae Park wrote:
> > Commit dd06e72e68bc ("Compiler Attributes: Add __counted_by macro")
> > added __counted_by() annotation.  The underlying attribute for the
> > feature is still under development, but adopting it can improve the
> > readability of the code.  Apply it to four dynamic arrays in DAMON sysfs
> > code.
> > 
> > Signed-off-by: SeongJae Park <sj@kernel.org>
> > ---
> >  mm/damon/sysfs.c | 8 ++++----
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> > 
> > diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
> > index 808a8efe0523..36a176f38726 100644
> > --- a/mm/damon/sysfs.c
> > +++ b/mm/damon/sysfs.c
> > @@ -93,7 +93,7 @@ static const struct kobj_type damon_sysfs_region_ktype = {
> > 
> >  struct damon_sysfs_regions {
> >  	struct kobject kobj;
> > -	struct damon_sysfs_region **regions_arr;
> > +	struct damon_sysfs_region **regions_arr __counted_by(nr);
> >  	int nr;
> >  };
> 
> Unfortunately this isn't supported yet for non-flexible-array-members:
> 
> mm/damon/sysfs.c:96:14: error: 'counted_by' attribute may not be specified for a non-array field
>    96 |         struct damon_sysfs_region **regions_arr __counted_by(nr);
>       |                                     ^~~~~
> 
> We'll have to wait a bit before we can add this patch.

Thank you for checking this and let me know.  Ok, I will wait.

> Thank you for
> getting it ready, though!

Owing to your previous contributions.  Thank you for helping me make DAMON code
better to read :)

> This support is next in line. :)
> 
> The FAM support is likely ready to land, though[1]. I just tested it
> today.
> 
> -Kees
> 
> [1] https://gcc.gnu.org/pipermail/gcc-patches/2023-August/628459.html
> 
> -- 
> Kees Cook
> 


Thanks,
SJ
diff mbox series

Patch

diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index 808a8efe0523..36a176f38726 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -93,7 +93,7 @@  static const struct kobj_type damon_sysfs_region_ktype = {
 
 struct damon_sysfs_regions {
 	struct kobject kobj;
-	struct damon_sysfs_region **regions_arr;
+	struct damon_sysfs_region **regions_arr __counted_by(nr);
 	int nr;
 };
 
@@ -289,7 +289,7 @@  static const struct kobj_type damon_sysfs_target_ktype = {
 
 struct damon_sysfs_targets {
 	struct kobject kobj;
-	struct damon_sysfs_target **targets_arr;
+	struct damon_sysfs_target **targets_arr __counted_by(nr);
 	int nr;
 };
 
@@ -812,7 +812,7 @@  static const struct kobj_type damon_sysfs_context_ktype = {
 
 struct damon_sysfs_contexts {
 	struct kobject kobj;
-	struct damon_sysfs_context **contexts_arr;
+	struct damon_sysfs_context **contexts_arr __counted_by(nr);
 	int nr;
 };
 
@@ -1590,7 +1590,7 @@  static const struct kobj_type damon_sysfs_kdamond_ktype = {
 
 struct damon_sysfs_kdamonds {
 	struct kobject kobj;
-	struct damon_sysfs_kdamond **kdamonds_arr;
+	struct damon_sysfs_kdamond **kdamonds_arr __counted_by(nr);
 	int nr;
 };