* [PATCH 1/1 linux-next] ocfs2: remove unnecessary sizeof(char)
@ 2014-12-22 19:05 Fabian Frederick
2014-12-22 21:35 ` [Ocfs2-devel] " Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: Fabian Frederick @ 2014-12-22 19:05 UTC (permalink / raw)
To: linux-kernel; +Cc: joe, Fabian Frederick, Mark Fasheh, Joel Becker, ocfs2-devel
sizeof(char) is always 1.
Suggested-by: Joe Perches <joe@perches.com>
Signed-off-by: Fabian Frederick <fabf@skynet.be>
---
fs/ocfs2/journal.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c
index e238bbc..750597c 100644
--- a/fs/ocfs2/journal.c
+++ b/fs/ocfs2/journal.c
@@ -129,8 +129,8 @@ int ocfs2_compute_replay_slots(struct ocfs2_super *osb)
if (osb->replay_map)
return 0;
- replay_map = kzalloc(sizeof(struct ocfs2_replay_map) +
- (osb->max_slots * sizeof(char)), GFP_KERNEL);
+ replay_map = kzalloc(sizeof(struct ocfs2_replay_map) + osb->max_slots,
+ GFP_KERNEL);
if (!replay_map) {
mlog_errno(-ENOMEM);
--
1.9.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Ocfs2-devel] [PATCH 1/1 linux-next] ocfs2: remove unnecessary sizeof(char)
2014-12-22 19:05 [PATCH 1/1 linux-next] ocfs2: remove unnecessary sizeof(char) Fabian Frederick
@ 2014-12-22 21:35 ` Andrew Morton
2014-12-23 11:14 ` Rasmus Villemoes
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2014-12-22 21:35 UTC (permalink / raw)
To: Fabian Frederick; +Cc: linux-kernel, joe, ocfs2-devel, Mark Fasheh
On Mon, 22 Dec 2014 20:05:09 +0100 Fabian Frederick <fabf@skynet.be> wrote:
> sizeof(char) is always 1.
>
> ...
>
> --- a/fs/ocfs2/journal.c
> +++ b/fs/ocfs2/journal.c
> @@ -129,8 +129,8 @@ int ocfs2_compute_replay_slots(struct ocfs2_super *osb)
> if (osb->replay_map)
> return 0;
>
> - replay_map = kzalloc(sizeof(struct ocfs2_replay_map) +
> - (osb->max_slots * sizeof(char)), GFP_KERNEL);
> + replay_map = kzalloc(sizeof(struct ocfs2_replay_map) + osb->max_slots,
> + GFP_KERNEL);
>
> if (!replay_map) {
> mlog_errno(-ENOMEM);
I dunno. The code at present isn't particularly idiomatic, but it has
some documentation value and says "I know what I'm doing".
It would be better if it was
kzalloc(sizeof(struct ocfs2_replay_map) *
sizeof(struct ocfs2_replay_map.rm_replay_slots[0]), ...);
And it would be better if C permitted that ;)
kzalloc(sizeof(struct ocfs2_replay_map) *
sizeof((struct ocfs2_replay_map *)0)->rm_replay_slots[0]), ...);
yuk.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Ocfs2-devel] [PATCH 1/1 linux-next] ocfs2: remove unnecessary sizeof(char)
2014-12-22 21:35 ` [Ocfs2-devel] " Andrew Morton
@ 2014-12-23 11:14 ` Rasmus Villemoes
0 siblings, 0 replies; 3+ messages in thread
From: Rasmus Villemoes @ 2014-12-23 11:14 UTC (permalink / raw)
To: Andrew Morton
Cc: Fabian Frederick, linux-kernel, joe, ocfs2-devel, Mark Fasheh
On Mon, Dec 22 2014, Andrew Morton <akpm@linux-foundation.org> wrote:
> On Mon, 22 Dec 2014 20:05:09 +0100 Fabian Frederick <fabf@skynet.be> wrote:
>
>>
>> - replay_map = kzalloc(sizeof(struct ocfs2_replay_map) +
>> - (osb->max_slots * sizeof(char)), GFP_KERNEL);
>> + replay_map = kzalloc(sizeof(struct ocfs2_replay_map) + osb->max_slots,
>> + GFP_KERNEL);
>>
>
> I dunno. The code at present isn't particularly idiomatic, but it has
> some documentation value and says "I know what I'm doing".
>
> It would be better if it was
>
> kzalloc(sizeof(struct ocfs2_replay_map) *
> sizeof(struct ocfs2_replay_map.rm_replay_slots[0]), ...);
>
> And it would be better if C permitted that ;)
>
> kzalloc(sizeof(struct ocfs2_replay_map) *
> sizeof((struct ocfs2_replay_map *)0)->rm_replay_slots[0]), ...);
>
> yuk.
Well, the yuckiness could be hidden behind FIELD_SIZEOF. CodingStyle
explicitly mentions that macro. No opinion on whether it's worth it in
this case.
Rasmus
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-12-23 11:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-22 19:05 [PATCH 1/1 linux-next] ocfs2: remove unnecessary sizeof(char) Fabian Frederick
2014-12-22 21:35 ` [Ocfs2-devel] " Andrew Morton
2014-12-23 11:14 ` Rasmus Villemoes
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®