Skip to content

Commit

Permalink
bcache: not use hard coded memset size in bch_cache_accounting_clear()
Browse files Browse the repository at this point in the history
In stats.c:bch_cache_accounting_clear(), a hard coded number '7' is
used in memset(). It is because in struct cache_stats, there are 7
atomic_t type members. This is not good when new members added into
struct stats, the hard coded number will only clear part of memory.

This patch replaces 'sizeof(unsigned long) * 7' by more generic
'sizeof(struct cache_stats))', to avoid potential error if new
member added into struct cache_stats.

Signed-off-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Coly Li authored and axboe committed Feb 9, 2019
1 parent 9951379 commit 83ff931
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/md/bcache/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void bch_cache_accounting_clear(struct cache_accounting *acc)
{
memset(&acc->total.cache_hits,
0,
sizeof(unsigned long) * 7);
sizeof(struct cache_stats));
}

void bch_cache_accounting_destroy(struct cache_accounting *acc)
Expand Down

0 comments on commit 83ff931

Please sign in to comment.