* [PATCH 1/2] ubifs: fix sort function prototype
@ 2024-02-13 9:54 Arnd Bergmann
2024-02-13 9:54 ` [PATCH 2/2] ubifs: fix function pointer cast warnings Arnd Bergmann
2024-02-18 1:25 ` [PATCH 1/2] ubifs: fix sort function prototype Zhihao Cheng
0 siblings, 2 replies; 4+ messages in thread
From: Arnd Bergmann @ 2024-02-13 9:54 UTC (permalink / raw)
To: Richard Weinberger, Nathan Chancellor, Adrian Hunter,
Artem Bityutskiy
Cc: Arnd Bergmann, Nick Desaulniers, Bill Wendling, Justin Stitt,
linux-mtd, linux-kernel, llvm
From: Arnd Bergmann <arnd@arndb.de>
The global sort() function expects a callback pointer to a function with two
void* arguments, but ubifs has a function with specific object types, which
causes a warning in clang-16 and higher:
fs/ubifs/lprops.c:1272:9: error: cast from 'int (*)(struct ubifs_info *, const struct ubifs_lprops *, int, struct ubifs_lp_stats *)' to 'ubifs_lpt_scan_callback' (aka 'int (*)(struct ubifs_info *, const struct ubifs_lprops *, int, void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]
1272 | (ubifs_lpt_scan_callback)scan_check_cb,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Change the prototype to the regular one and cast the object pointers
locally instead.
Fixes: 1e51764a3c2a ("UBIFS: add new flash file system")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
fs/ubifs/find.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/fs/ubifs/find.c b/fs/ubifs/find.c
index 873e6e1c92b5..1cb79b167a4f 100644
--- a/fs/ubifs/find.c
+++ b/fs/ubifs/find.c
@@ -726,11 +726,10 @@ int ubifs_find_free_leb_for_idx(struct ubifs_info *c)
return err;
}
-static int cmp_dirty_idx(const struct ubifs_lprops **a,
- const struct ubifs_lprops **b)
+static int cmp_dirty_idx(const void *a, const void *b)
{
- const struct ubifs_lprops *lpa = *a;
- const struct ubifs_lprops *lpb = *b;
+ const struct ubifs_lprops *lpa = *(const struct ubifs_lprops **)a;
+ const struct ubifs_lprops *lpb = *(const struct ubifs_lprops **)b;
return lpa->dirty + lpa->free - lpb->dirty - lpb->free;
}
@@ -754,7 +753,7 @@ int ubifs_save_dirty_idx_lnums(struct ubifs_info *c)
sizeof(void *) * c->dirty_idx.cnt);
/* Sort it so that the dirtiest is now at the end */
sort(c->dirty_idx.arr, c->dirty_idx.cnt, sizeof(void *),
- (int (*)(const void *, const void *))cmp_dirty_idx, NULL);
+ cmp_dirty_idx, NULL);
dbg_find("found %d dirty index LEBs", c->dirty_idx.cnt);
if (c->dirty_idx.cnt)
dbg_find("dirtiest index LEB is %d with dirty %d and free %d",
--
2.39.2
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 2/2] ubifs: fix function pointer cast warnings 2024-02-13 9:54 [PATCH 1/2] ubifs: fix sort function prototype Arnd Bergmann @ 2024-02-13 9:54 ` Arnd Bergmann 2024-02-18 1:40 ` Zhihao Cheng 2024-02-18 1:25 ` [PATCH 1/2] ubifs: fix sort function prototype Zhihao Cheng 1 sibling, 1 reply; 4+ messages in thread From: Arnd Bergmann @ 2024-02-13 9:54 UTC (permalink / raw) To: Richard Weinberger, Nathan Chancellor Cc: Arnd Bergmann, Nick Desaulniers, Bill Wendling, Justin Stitt, linux-mtd, linux-kernel, llvm From: Arnd Bergmann <arnd@arndb.de> ubifs has a number of callback functions for ubifs_lpt_scan_nolock() using two different prototypes, either passing a struct scan_data or a struct ubifs_lp_stats, but the caller expects a void pointer instead. clang-16 now warns about this: fs/ubifs/find.c:170:9: error: cast from 'int (*)(struct ubifs_info *, const struct ubifs_lprops *, int, struct scan_data *)' to 'ubifs_lpt_scan_callback' (aka 'int (*)(struct ubifs_info *, const struct ubifs_lprops *, int, void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict] 170 | (ubifs_lpt_scan_callback)scan_for_dirty_cb, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ fs/ubifs/find.c:449:9: error: cast from 'int (*)(struct ubifs_info *, const struct ubifs_lprops *, int, struct scan_data *)' to 'ubifs_lpt_scan_callback' (aka 'int (*)(struct ubifs_info *, const struct ubifs_lprops *, int, void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict] 449 | (ubifs_lpt_scan_callback)scan_for_free_cb, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Change all of these callback functions to actually take the void * argument that is passed by their caller. Signed-off-by: Arnd Bergmann <arnd@arndb.de> --- fs/ubifs/find.c | 23 ++++++++++++----------- fs/ubifs/lprops.c | 6 +++--- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/fs/ubifs/find.c b/fs/ubifs/find.c index 1cb79b167a4f..6ebf3c04ac5f 100644 --- a/fs/ubifs/find.c +++ b/fs/ubifs/find.c @@ -82,8 +82,9 @@ static int valuable(struct ubifs_info *c, const struct ubifs_lprops *lprops) */ static int scan_for_dirty_cb(struct ubifs_info *c, const struct ubifs_lprops *lprops, int in_tree, - struct scan_data *data) + void *arg) { + struct scan_data *data = arg; int ret = LPT_SCAN_CONTINUE; /* Exclude LEBs that are currently in use */ @@ -166,8 +167,7 @@ static const struct ubifs_lprops *scan_for_dirty(struct ubifs_info *c, data.pick_free = pick_free; data.lnum = -1; data.exclude_index = exclude_index; - err = ubifs_lpt_scan_nolock(c, -1, c->lscan_lnum, - (ubifs_lpt_scan_callback)scan_for_dirty_cb, + err = ubifs_lpt_scan_nolock(c, -1, c->lscan_lnum, scan_for_dirty_cb, &data); if (err) return ERR_PTR(err); @@ -349,8 +349,9 @@ int ubifs_find_dirty_leb(struct ubifs_info *c, struct ubifs_lprops *ret_lp, */ static int scan_for_free_cb(struct ubifs_info *c, const struct ubifs_lprops *lprops, int in_tree, - struct scan_data *data) + void *arg) { + struct scan_data *data = arg; int ret = LPT_SCAN_CONTINUE; /* Exclude LEBs that are currently in use */ @@ -446,7 +447,7 @@ const struct ubifs_lprops *do_find_free_space(struct ubifs_info *c, data.pick_free = pick_free; data.lnum = -1; err = ubifs_lpt_scan_nolock(c, -1, c->lscan_lnum, - (ubifs_lpt_scan_callback)scan_for_free_cb, + scan_for_free_cb, &data); if (err) return ERR_PTR(err); @@ -589,8 +590,9 @@ int ubifs_find_free_space(struct ubifs_info *c, int min_space, int *offs, */ static int scan_for_idx_cb(struct ubifs_info *c, const struct ubifs_lprops *lprops, int in_tree, - struct scan_data *data) + void *arg) { + struct scan_data *data = arg; int ret = LPT_SCAN_CONTINUE; /* Exclude LEBs that are currently in use */ @@ -625,8 +627,7 @@ static const struct ubifs_lprops *scan_for_leb_for_idx(struct ubifs_info *c) int err; data.lnum = -1; - err = ubifs_lpt_scan_nolock(c, -1, c->lscan_lnum, - (ubifs_lpt_scan_callback)scan_for_idx_cb, + err = ubifs_lpt_scan_nolock(c, -1, c->lscan_lnum, scan_for_idx_cb, &data); if (err) return ERR_PTR(err); @@ -781,8 +782,9 @@ int ubifs_save_dirty_idx_lnums(struct ubifs_info *c) */ static int scan_dirty_idx_cb(struct ubifs_info *c, const struct ubifs_lprops *lprops, int in_tree, - struct scan_data *data) + void *arg) { + struct scan_data *data = arg; int ret = LPT_SCAN_CONTINUE; /* Exclude LEBs that are currently in use */ @@ -841,8 +843,7 @@ static int find_dirty_idx_leb(struct ubifs_info *c) if (c->pnodes_have >= c->pnode_cnt) /* All pnodes are in memory, so skip scan */ return -ENOSPC; - err = ubifs_lpt_scan_nolock(c, -1, c->lscan_lnum, - (ubifs_lpt_scan_callback)scan_dirty_idx_cb, + err = ubifs_lpt_scan_nolock(c, -1, c->lscan_lnum, scan_dirty_idx_cb, &data); if (err) return err; diff --git a/fs/ubifs/lprops.c b/fs/ubifs/lprops.c index 6d6cd85c2b4c..a11c3dab7e16 100644 --- a/fs/ubifs/lprops.c +++ b/fs/ubifs/lprops.c @@ -1014,8 +1014,9 @@ void dbg_check_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat, */ static int scan_check_cb(struct ubifs_info *c, const struct ubifs_lprops *lp, int in_tree, - struct ubifs_lp_stats *lst) + void *arg) { + struct ubifs_lp_stats *lst = arg; struct ubifs_scan_leb *sleb; struct ubifs_scan_node *snod; int cat, lnum = lp->lnum, is_idx = 0, used = 0, free, dirty, ret; @@ -1269,8 +1270,7 @@ int dbg_check_lprops(struct ubifs_info *c) memset(&lst, 0, sizeof(struct ubifs_lp_stats)); err = ubifs_lpt_scan_nolock(c, c->main_first, c->leb_cnt - 1, - (ubifs_lpt_scan_callback)scan_check_cb, - &lst); + scan_check_cb, &lst); if (err && err != -ENOSPC) goto out; -- 2.39.2 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] ubifs: fix function pointer cast warnings 2024-02-13 9:54 ` [PATCH 2/2] ubifs: fix function pointer cast warnings Arnd Bergmann @ 2024-02-18 1:40 ` Zhihao Cheng 0 siblings, 0 replies; 4+ messages in thread From: Zhihao Cheng @ 2024-02-18 1:40 UTC (permalink / raw) To: Arnd Bergmann, Richard Weinberger, Nathan Chancellor Cc: Arnd Bergmann, Nick Desaulniers, Bill Wendling, Justin Stitt, linux-mtd, linux-kernel, llvm 在 2024/2/13 17:54, Arnd Bergmann 写道: > From: Arnd Bergmann <arnd@arndb.de> > > ubifs has a number of callback functions for ubifs_lpt_scan_nolock() using > two different prototypes, either passing a struct scan_data or > a struct ubifs_lp_stats, but the caller expects a void pointer instead. > > clang-16 now warns about this: > > fs/ubifs/find.c:170:9: error: cast from 'int (*)(struct ubifs_info *, const struct ubifs_lprops *, int, struct scan_data *)' to 'ubifs_lpt_scan_callback' (aka 'int (*)(struct ubifs_info *, const struct ubifs_lprops *, int, void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict] > 170 | (ubifs_lpt_scan_callback)scan_for_dirty_cb, > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > fs/ubifs/find.c:449:9: error: cast from 'int (*)(struct ubifs_info *, const struct ubifs_lprops *, int, struct scan_data *)' to 'ubifs_lpt_scan_callback' (aka 'int (*)(struct ubifs_info *, const struct ubifs_lprops *, int, void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict] > 449 | (ubifs_lpt_scan_callback)scan_for_free_cb, > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > Change all of these callback functions to actually take the void * argument > that is passed by their caller. > > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > --- > fs/ubifs/find.c | 23 ++++++++++++----------- > fs/ubifs/lprops.c | 6 +++--- > 2 files changed, 15 insertions(+), 14 deletions(-) > Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com> > diff --git a/fs/ubifs/find.c b/fs/ubifs/find.c > index 1cb79b167a4f..6ebf3c04ac5f 100644 > --- a/fs/ubifs/find.c > +++ b/fs/ubifs/find.c > @@ -82,8 +82,9 @@ static int valuable(struct ubifs_info *c, const struct ubifs_lprops *lprops) > */ > static int scan_for_dirty_cb(struct ubifs_info *c, > const struct ubifs_lprops *lprops, int in_tree, > - struct scan_data *data) > + void *arg) > { > + struct scan_data *data = arg; > int ret = LPT_SCAN_CONTINUE; > > /* Exclude LEBs that are currently in use */ > @@ -166,8 +167,7 @@ static const struct ubifs_lprops *scan_for_dirty(struct ubifs_info *c, > data.pick_free = pick_free; > data.lnum = -1; > data.exclude_index = exclude_index; > - err = ubifs_lpt_scan_nolock(c, -1, c->lscan_lnum, > - (ubifs_lpt_scan_callback)scan_for_dirty_cb, > + err = ubifs_lpt_scan_nolock(c, -1, c->lscan_lnum, scan_for_dirty_cb, > &data); > if (err) > return ERR_PTR(err); > @@ -349,8 +349,9 @@ int ubifs_find_dirty_leb(struct ubifs_info *c, struct ubifs_lprops *ret_lp, > */ > static int scan_for_free_cb(struct ubifs_info *c, > const struct ubifs_lprops *lprops, int in_tree, > - struct scan_data *data) > + void *arg) > { > + struct scan_data *data = arg; > int ret = LPT_SCAN_CONTINUE; > > /* Exclude LEBs that are currently in use */ > @@ -446,7 +447,7 @@ const struct ubifs_lprops *do_find_free_space(struct ubifs_info *c, > data.pick_free = pick_free; > data.lnum = -1; > err = ubifs_lpt_scan_nolock(c, -1, c->lscan_lnum, > - (ubifs_lpt_scan_callback)scan_for_free_cb, > + scan_for_free_cb, > &data); > if (err) > return ERR_PTR(err); > @@ -589,8 +590,9 @@ int ubifs_find_free_space(struct ubifs_info *c, int min_space, int *offs, > */ > static int scan_for_idx_cb(struct ubifs_info *c, > const struct ubifs_lprops *lprops, int in_tree, > - struct scan_data *data) > + void *arg) > { > + struct scan_data *data = arg; > int ret = LPT_SCAN_CONTINUE; > > /* Exclude LEBs that are currently in use */ > @@ -625,8 +627,7 @@ static const struct ubifs_lprops *scan_for_leb_for_idx(struct ubifs_info *c) > int err; > > data.lnum = -1; > - err = ubifs_lpt_scan_nolock(c, -1, c->lscan_lnum, > - (ubifs_lpt_scan_callback)scan_for_idx_cb, > + err = ubifs_lpt_scan_nolock(c, -1, c->lscan_lnum, scan_for_idx_cb, > &data); > if (err) > return ERR_PTR(err); > @@ -781,8 +782,9 @@ int ubifs_save_dirty_idx_lnums(struct ubifs_info *c) > */ > static int scan_dirty_idx_cb(struct ubifs_info *c, > const struct ubifs_lprops *lprops, int in_tree, > - struct scan_data *data) > + void *arg) > { > + struct scan_data *data = arg; > int ret = LPT_SCAN_CONTINUE; > > /* Exclude LEBs that are currently in use */ > @@ -841,8 +843,7 @@ static int find_dirty_idx_leb(struct ubifs_info *c) > if (c->pnodes_have >= c->pnode_cnt) > /* All pnodes are in memory, so skip scan */ > return -ENOSPC; > - err = ubifs_lpt_scan_nolock(c, -1, c->lscan_lnum, > - (ubifs_lpt_scan_callback)scan_dirty_idx_cb, > + err = ubifs_lpt_scan_nolock(c, -1, c->lscan_lnum, scan_dirty_idx_cb, > &data); > if (err) > return err; > diff --git a/fs/ubifs/lprops.c b/fs/ubifs/lprops.c > index 6d6cd85c2b4c..a11c3dab7e16 100644 > --- a/fs/ubifs/lprops.c > +++ b/fs/ubifs/lprops.c > @@ -1014,8 +1014,9 @@ void dbg_check_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat, > */ > static int scan_check_cb(struct ubifs_info *c, > const struct ubifs_lprops *lp, int in_tree, > - struct ubifs_lp_stats *lst) > + void *arg) > { > + struct ubifs_lp_stats *lst = arg; > struct ubifs_scan_leb *sleb; > struct ubifs_scan_node *snod; > int cat, lnum = lp->lnum, is_idx = 0, used = 0, free, dirty, ret; > @@ -1269,8 +1270,7 @@ int dbg_check_lprops(struct ubifs_info *c) > > memset(&lst, 0, sizeof(struct ubifs_lp_stats)); > err = ubifs_lpt_scan_nolock(c, c->main_first, c->leb_cnt - 1, > - (ubifs_lpt_scan_callback)scan_check_cb, > - &lst); > + scan_check_cb, &lst); > if (err && err != -ENOSPC) > goto out; > > ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] ubifs: fix sort function prototype 2024-02-13 9:54 [PATCH 1/2] ubifs: fix sort function prototype Arnd Bergmann 2024-02-13 9:54 ` [PATCH 2/2] ubifs: fix function pointer cast warnings Arnd Bergmann @ 2024-02-18 1:25 ` Zhihao Cheng 1 sibling, 0 replies; 4+ messages in thread From: Zhihao Cheng @ 2024-02-18 1:25 UTC (permalink / raw) To: Arnd Bergmann, Richard Weinberger, Nathan Chancellor, Adrian Hunter, Artem Bityutskiy Cc: Arnd Bergmann, Nick Desaulniers, Bill Wendling, Justin Stitt, linux-mtd, linux-kernel, llvm 在 2024/2/13 17:54, Arnd Bergmann 写道: > From: Arnd Bergmann <arnd@arndb.de> > > The global sort() function expects a callback pointer to a function with two > void* arguments, but ubifs has a function with specific object types, which > causes a warning in clang-16 and higher: > > fs/ubifs/lprops.c:1272:9: error: cast from 'int (*)(struct ubifs_info *, const struct ubifs_lprops *, int, struct ubifs_lp_stats *)' to 'ubifs_lpt_scan_callback' (aka 'int (*)(struct ubifs_info *, const struct ubifs_lprops *, int, void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict] > 1272 | (ubifs_lpt_scan_callback)scan_check_cb, > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > Change the prototype to the regular one and cast the object pointers > locally instead. > > Fixes: 1e51764a3c2a ("UBIFS: add new flash file system") > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > --- > fs/ubifs/find.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com> > > diff --git a/fs/ubifs/find.c b/fs/ubifs/find.c > index 873e6e1c92b5..1cb79b167a4f 100644 > --- a/fs/ubifs/find.c > +++ b/fs/ubifs/find.c > @@ -726,11 +726,10 @@ int ubifs_find_free_leb_for_idx(struct ubifs_info *c) > return err; > } > > -static int cmp_dirty_idx(const struct ubifs_lprops **a, > - const struct ubifs_lprops **b) > +static int cmp_dirty_idx(const void *a, const void *b) > { > - const struct ubifs_lprops *lpa = *a; > - const struct ubifs_lprops *lpb = *b; > + const struct ubifs_lprops *lpa = *(const struct ubifs_lprops **)a; > + const struct ubifs_lprops *lpb = *(const struct ubifs_lprops **)b; > > return lpa->dirty + lpa->free - lpb->dirty - lpb->free; > } > @@ -754,7 +753,7 @@ int ubifs_save_dirty_idx_lnums(struct ubifs_info *c) > sizeof(void *) * c->dirty_idx.cnt); > /* Sort it so that the dirtiest is now at the end */ > sort(c->dirty_idx.arr, c->dirty_idx.cnt, sizeof(void *), > - (int (*)(const void *, const void *))cmp_dirty_idx, NULL); > + cmp_dirty_idx, NULL); > dbg_find("found %d dirty index LEBs", c->dirty_idx.cnt); > if (c->dirty_idx.cnt) > dbg_find("dirtiest index LEB is %d with dirty %d and free %d", > ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-02-18 1:40 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-02-13 9:54 [PATCH 1/2] ubifs: fix sort function prototype Arnd Bergmann 2024-02-13 9:54 ` [PATCH 2/2] ubifs: fix function pointer cast warnings Arnd Bergmann 2024-02-18 1:40 ` Zhihao Cheng 2024-02-18 1:25 ` [PATCH 1/2] ubifs: fix sort function prototype Zhihao Cheng
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox