* [PATCH 0/2] Cleanups and safer memory allocations
@ 2025-08-11 12:09 Liao Yuanhong
2025-08-11 12:09 ` [PATCH 1/2] bcachefs: Using vmalloc_array() for array space allocation Liao Yuanhong
2025-08-11 12:09 ` [PATCH 2/2] bcachefs: Remove redundant semicolons Liao Yuanhong
0 siblings, 2 replies; 5+ messages in thread
From: Liao Yuanhong @ 2025-08-11 12:09 UTC (permalink / raw)
To: Kent Overstreet, open list:BCACHEFS, open list; +Cc: Liao Yuanhong
Removed unnecessary semicolons and used vmalloc_array() for array space
allocation.
Liao Yuanhong (2):
bcachefs: Using vmalloc_array() for array space allocation
bcachefs: Remove redundant semicolons
fs/bcachefs/btree_key_cache.c | 2 +-
fs/bcachefs/btree_trans_commit.c | 4 ++--
fs/bcachefs/rebalance.c | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] bcachefs: Using vmalloc_array() for array space allocation
2025-08-11 12:09 [PATCH 0/2] Cleanups and safer memory allocations Liao Yuanhong
@ 2025-08-11 12:09 ` Liao Yuanhong
2025-08-11 12:50 ` Alan Huang
2025-08-11 12:09 ` [PATCH 2/2] bcachefs: Remove redundant semicolons Liao Yuanhong
1 sibling, 1 reply; 5+ messages in thread
From: Liao Yuanhong @ 2025-08-11 12:09 UTC (permalink / raw)
To: Kent Overstreet, open list:BCACHEFS, open list; +Cc: Liao Yuanhong
Replace kmalloc(size * sizeof) with kmalloc_array() for safer memory
allocation and overflow prevention.
Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
---
fs/bcachefs/btree_key_cache.c | 2 +-
fs/bcachefs/btree_trans_commit.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/bcachefs/btree_key_cache.c b/fs/bcachefs/btree_key_cache.c
index 4890cbc88e7c..8dd70024e513 100644
--- a/fs/bcachefs/btree_key_cache.c
+++ b/fs/bcachefs/btree_key_cache.c
@@ -136,7 +136,7 @@ static struct bkey_cached *__bkey_cached_alloc(unsigned key_u64s, gfp_t gfp)
struct bkey_cached *ck = kmem_cache_zalloc(bch2_key_cache, gfp);
if (unlikely(!ck))
return NULL;
- ck->k = kmalloc(key_u64s * sizeof(u64), gfp);
+ ck->k = kmalloc_array(key_u64s, sizeof(u64), gfp);
if (unlikely(!ck->k)) {
kmem_cache_free(bch2_key_cache, ck);
return NULL;
diff --git a/fs/bcachefs/btree_trans_commit.c b/fs/bcachefs/btree_trans_commit.c
index 4d58bdb233e9..4102a3cb2410 100644
--- a/fs/bcachefs/btree_trans_commit.c
+++ b/fs/bcachefs/btree_trans_commit.c
@@ -396,7 +396,7 @@ btree_key_can_insert_cached_slowpath(struct btree_trans *trans, unsigned flags,
bch2_trans_unlock_updates_write(trans);
bch2_trans_unlock(trans);
- new_k = kmalloc(new_u64s * sizeof(u64), GFP_KERNEL);
+ new_k = kmalloc_array(new_u64s, sizeof(u64), GFP_KERNEL);
if (!new_k) {
struct bch_fs *c = trans->c;
bch_err(c, "error allocating memory for key cache key, btree %s u64s %u",
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] bcachefs: Remove redundant semicolons
2025-08-11 12:09 [PATCH 0/2] Cleanups and safer memory allocations Liao Yuanhong
2025-08-11 12:09 ` [PATCH 1/2] bcachefs: Using vmalloc_array() for array space allocation Liao Yuanhong
@ 2025-08-11 12:09 ` Liao Yuanhong
1 sibling, 0 replies; 5+ messages in thread
From: Liao Yuanhong @ 2025-08-11 12:09 UTC (permalink / raw)
To: Kent Overstreet, open list:BCACHEFS, open list; +Cc: Liao Yuanhong
Remove redundant double semicolons (;;).
Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
---
fs/bcachefs/btree_trans_commit.c | 2 +-
fs/bcachefs/rebalance.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/bcachefs/btree_trans_commit.c b/fs/bcachefs/btree_trans_commit.c
index 4102a3cb2410..0d266de2689e 100644
--- a/fs/bcachefs/btree_trans_commit.c
+++ b/fs/bcachefs/btree_trans_commit.c
@@ -340,7 +340,7 @@ static inline void btree_insert_entry_checks(struct btree_trans *trans,
BUG_ON(i->cached != path->cached);
BUG_ON(i->cached &&
!i->key_cache_already_flushed &&
- bkey_deleted(&i->k->k));;
+ bkey_deleted(&i->k->k));
BUG_ON(i->level != path->level);
BUG_ON(i->btree_id != path->btree_id);
BUG_ON(i->bkey_type != __btree_node_type(path->level, path->btree_id));
diff --git a/fs/bcachefs/rebalance.c b/fs/bcachefs/rebalance.c
index e1db63d75a99..093c72baa6a6 100644
--- a/fs/bcachefs/rebalance.c
+++ b/fs/bcachefs/rebalance.c
@@ -304,7 +304,7 @@ static struct bkey_i *next_rebalance_entry(struct btree_trans *trans,
* work entries in a darray
*/
- BUG_ON(!buf->size);;
+ BUG_ON(!buf->size);
bch2_trans_begin(trans);
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] bcachefs: Using vmalloc_array() for array space allocation
2025-08-11 12:09 ` [PATCH 1/2] bcachefs: Using vmalloc_array() for array space allocation Liao Yuanhong
@ 2025-08-11 12:50 ` Alan Huang
2025-08-11 13:02 ` Liao Yuanhong
0 siblings, 1 reply; 5+ messages in thread
From: Alan Huang @ 2025-08-11 12:50 UTC (permalink / raw)
To: Liao Yuanhong; +Cc: Kent Overstreet, open list:BCACHEFS, open list
On Aug 11, 2025, at 20:09, Liao Yuanhong <liaoyuanhong@vivo.com> wrote:
>
> Replace kmalloc(size * sizeof) with kmalloc_array() for safer memory
> allocation and overflow prevention.
>
> Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
> ---
> fs/bcachefs/btree_key_cache.c | 2 +-
> fs/bcachefs/btree_trans_commit.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/bcachefs/btree_key_cache.c b/fs/bcachefs/btree_key_cache.c
> index 4890cbc88e7c..8dd70024e513 100644
> --- a/fs/bcachefs/btree_key_cache.c
> +++ b/fs/bcachefs/btree_key_cache.c
> @@ -136,7 +136,7 @@ static struct bkey_cached *__bkey_cached_alloc(unsigned key_u64s, gfp_t gfp)
> struct bkey_cached *ck = kmem_cache_zalloc(bch2_key_cache, gfp);
> if (unlikely(!ck))
> return NULL;
> - ck->k = kmalloc(key_u64s * sizeof(u64), gfp);
> + ck->k = kmalloc_array(key_u64s, sizeof(u64), gfp);
> if (unlikely(!ck->k)) {
> kmem_cache_free(bch2_key_cache, ck);
> return NULL;
> diff --git a/fs/bcachefs/btree_trans_commit.c b/fs/bcachefs/btree_trans_commit.c
> index 4d58bdb233e9..4102a3cb2410 100644
> --- a/fs/bcachefs/btree_trans_commit.c
> +++ b/fs/bcachefs/btree_trans_commit.c
> @@ -396,7 +396,7 @@ btree_key_can_insert_cached_slowpath(struct btree_trans *trans, unsigned flags,
> bch2_trans_unlock_updates_write(trans);
> bch2_trans_unlock(trans);
>
> - new_k = kmalloc(new_u64s * sizeof(u64), GFP_KERNEL);
> + new_k = kmalloc_array(new_u64s, sizeof(u64), GFP_KERNEL);
No, it’s not an array.
> if (!new_k) {
> struct bch_fs *c = trans->c;
> bch_err(c, "error allocating memory for key cache key, btree %s u64s %u",
> --
> 2.34.1
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] bcachefs: Using vmalloc_array() for array space allocation
2025-08-11 12:50 ` Alan Huang
@ 2025-08-11 13:02 ` Liao Yuanhong
0 siblings, 0 replies; 5+ messages in thread
From: Liao Yuanhong @ 2025-08-11 13:02 UTC (permalink / raw)
To: Alan Huang; +Cc: Kent Overstreet, open list:BCACHEFS, open list
On 8/11/2025 8:50 PM, Alan Huang wrote:
> [You don't often get email from mmpgouride@gmail.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> On Aug 11, 2025, at 20:09, Liao Yuanhong <liaoyuanhong@vivo.com> wrote:
>> Replace kmalloc(size * sizeof) with kmalloc_array() for safer memory
>> allocation and overflow prevention.
>>
>> Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
>> ---
>> fs/bcachefs/btree_key_cache.c | 2 +-
>> fs/bcachefs/btree_trans_commit.c | 2 +-
>> 2 files changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/bcachefs/btree_key_cache.c b/fs/bcachefs/btree_key_cache.c
>> index 4890cbc88e7c..8dd70024e513 100644
>> --- a/fs/bcachefs/btree_key_cache.c
>> +++ b/fs/bcachefs/btree_key_cache.c
>> @@ -136,7 +136,7 @@ static struct bkey_cached *__bkey_cached_alloc(unsigned key_u64s, gfp_t gfp)
>> struct bkey_cached *ck = kmem_cache_zalloc(bch2_key_cache, gfp);
>> if (unlikely(!ck))
>> return NULL;
>> - ck->k = kmalloc(key_u64s * sizeof(u64), gfp);
>> + ck->k = kmalloc_array(key_u64s, sizeof(u64), gfp);
>> if (unlikely(!ck->k)) {
>> kmem_cache_free(bch2_key_cache, ck);
>> return NULL;
>> diff --git a/fs/bcachefs/btree_trans_commit.c b/fs/bcachefs/btree_trans_commit.c
>> index 4d58bdb233e9..4102a3cb2410 100644
>> --- a/fs/bcachefs/btree_trans_commit.c
>> +++ b/fs/bcachefs/btree_trans_commit.c
>> @@ -396,7 +396,7 @@ btree_key_can_insert_cached_slowpath(struct btree_trans *trans, unsigned flags,
>> bch2_trans_unlock_updates_write(trans);
>> bch2_trans_unlock(trans);
>>
>> - new_k = kmalloc(new_u64s * sizeof(u64), GFP_KERNEL);
>> + new_k = kmalloc_array(new_u64s, sizeof(u64), GFP_KERNEL);
> No, it’s not an array.
Yes, there is a problem with this patch. Please ignore it.
Thanks,
Liao
>> if (!new_k) {
>> struct bch_fs *c = trans->c;
>> bch_err(c, "error allocating memory for key cache key, btree %s u64s %u",
>> --
>> 2.34.1
>>
>>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-08-11 13:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-11 12:09 [PATCH 0/2] Cleanups and safer memory allocations Liao Yuanhong
2025-08-11 12:09 ` [PATCH 1/2] bcachefs: Using vmalloc_array() for array space allocation Liao Yuanhong
2025-08-11 12:50 ` Alan Huang
2025-08-11 13:02 ` Liao Yuanhong
2025-08-11 12:09 ` [PATCH 2/2] bcachefs: Remove redundant semicolons Liao Yuanhong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®