lkml.org 
[lkml]   [2005]   [Aug]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH][FAT] FAT dirent scan with hin take #3
On 8/31/05, Machida, Hiroyuki <machida@sm.sony.co.jp> wrote:
> How about this ?
>
> if (!MSDOS_I(dir)->scan_hints) {
> hints = kcalllo(....);
>
> down
> if (MSDOS_I(dir)->scan_hints) {
> up
> goto already_allocated;
> }
> if (hints)
> MSDOS_I(dir)->scan_hints = hints;
> up
> }
> return (hints == 0) ? -ENOMEM : 0;
>
> already_allocated:
> kfree(hints); /* kfree accepts NULL */
> return 0;

After finally understanding what you're doing, how about:

static inline int hint_allocate(struct inode *dir)
{
loff_t *hints;
int err = 0;

if (!MSDOS_I(dir)->scan_hints)
return 0;

hints = kcalloc(FAT_SCAN_NWAY, sizeof(loff_t), GFP_KERNEL);
if (!hints)
err = -ENOMEM;

down(&MSDOS_I(dir)->scan_lock);
/*
* We allocated memory without scan_lock so lets make sure
* no other thread completed hint_allocate() before us.
*/
if (!MSDOS_I(dir)->scan_hints) {
MSDOS_I(dir)->scan_hints = hints;
hints = NULL;
}
up(&MSDOS_I(dir)->scan_lock);

kfree(hints);
return err;
}

Pekka
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-08-31 15:53    [W:0.050 / U:0.992 seconds]
©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site