* LogFS: confused with using s64 and u64
@ 2008-08-08 21:12 Alexander Beregalov
2008-08-09 11:16 ` Jörn Engel
0 siblings, 1 reply; 2+ messages in thread
From: Alexander Beregalov @ 2008-08-08 21:12 UTC (permalink / raw)
To: joern, linux-kernel
Hi Joern
I am a bit confused with mixing signed and unsigned types here:
static inline u64 dev_ofs(struct super_block *sb, u32 segno, u32 ofs)
{
return ((u64)segno << logfs_super(sb)->s_segshift) + ofs;
}
static s64 logfs_get_free_bytes(struct logfs_area *area, size_t bytes)
{
s32 ofs;
...
ofs = area->a_used_bytes;
...
return dev_ofs(area->a_sb, area->a_segno, ofs);
}
Can you please explain why do you use s64 for function which returns u64?
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: LogFS: confused with using s64 and u64
2008-08-08 21:12 LogFS: confused with using s64 and u64 Alexander Beregalov
@ 2008-08-09 11:16 ` Jörn Engel
0 siblings, 0 replies; 2+ messages in thread
From: Jörn Engel @ 2008-08-09 11:16 UTC (permalink / raw)
To: Alexander Beregalov; +Cc: linux-kernel
On Sat, 9 August 2008 01:12:36 +0400, Alexander Beregalov wrote:
>
> I am a bit confused with mixing signed and unsigned types here:
>
>
> static inline u64 dev_ofs(struct super_block *sb, u32 segno, u32 ofs)
> {
> return ((u64)segno << logfs_super(sb)->s_segshift) + ofs;
> }
>
> static s64 logfs_get_free_bytes(struct logfs_area *area, size_t bytes)
> {
> s32 ofs;
> ...
> ofs = area->a_used_bytes;
> ...
> return dev_ofs(area->a_sb, area->a_segno, ofs);
> }
>
> Can you please explain why do you use s64 for function which returns u64?
Sloppiness. Until the 64bit limit actually gets close, I prefer to use
negative return values to indicate errors. It would be possible to have
a seperate return value, as jffs2 does. But functions with two return
values are just icky. So many functions return s64
Functions that never return errors tend to use u64 instead. And I mix
them fairly liberally, "knowing" (as a programmer) that u64 will never
overflow into a negative s64.
Some sort of cleanup in that area surely wouldn't hurt.
Jörn
--
Don't patch bad code, rewrite it.
-- Kernigham and Pike, according to Rusty
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-08-09 11:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-08 21:12 LogFS: confused with using s64 and u64 Alexander Beregalov
2008-08-09 11:16 ` Jörn Engel
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®