mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Machida, Hiroyuki" <machida@sm.sony.co.jp>
To: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: linux-kernel@vger.kernel.org, hirofumi@mail.parknet.co.jp
Subject: Re: [PATCH][FAT] FAT dirent scan with hin take #3
Date: Wed, 31 Aug 2005 21:57:50 +0900	[thread overview]
Message-ID: <4315A94E.3030901@sm.sony.co.jp> (raw)
In-Reply-To: <84144f0205083103005b791f4d@mail.gmail.com>

Hi,

Pekka Enberg wrote:
> Hi,
> 
> On 8/31/05, Machida, Hiroyuki <machida@sm.sony.co.jp> wrote:
> 
>>+inline
>>+static int hint_allocate(struct inode *dir)
>>+{
>>+       loff_t *hints;
>>+       int err = 0;
>>+
>>+       if (!MSDOS_I(dir)->scan_hints) {
>>+               hints = kcalloc(FAT_SCAN_NWAY, sizeof(loff_t), GFP_KERNEL);
>>+               if (!hints)
>>+                       err = -ENOMEM;
> 
> 
> Better to bail out here as...
> 
> 
>>+
>>+               down(&MSDOS_I(dir)->scan_lock);
>>+               if (MSDOS_I(dir)->scan_hints)
>>+                       err = -EINVAL;
> 
> 
> ...you might overwrite -ENOMEM here masking the real problem.
> 

It's ok. If MSDOS_I(dir)->scan_hints isn't NULL, it's not error case.
We need just kfree(hints) and return 0.(Assuming  kfree() accepts NULL)
I think EINVAL confuse you.
> 
>>+               if (!err)
>>+                       MSDOS_I(dir)->scan_hints = hints;
>>+               up(&MSDOS_I(dir)->scan_lock);
>>+               if (err == -EINVAL) {
> 
> 
> Gotos would make error handling much cleaner.
> 
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;
		


> 
>>+inline
>>+static int hint_index_body(const unsigned char *name, int name_len, int check_null)
> 
> 
> Please consider calling this __hint_index() instead as per normal
> naming conventions.

Agree.

> 
>>+{
>>+       int i;
>>+       int val = 0;
>>+       unsigned char *p = (unsigned char *) name;
>>+       int id = current->pid;
>>+
>>+       for (i=0; i<name_len; i++) {
>>+               if (check_null && !*p) break;
> 
> 
> Please put break on separate line. You still have quite a few of these.

Agree

> 
> 
>>+               val = ((val << 1) & 0xfe) | ((val & 0x80) ? 1 : 0);
>>+               val ^= *p;
>>+               p ++;
>>+       }
>>+       id = ((id >> 8) & 0xf) ^ (id & 0xf);
>>+       val = (val << 1) | (id & 1);
>>+       return val & (FAT_SCAN_NWAY-1);
>>+}
> 
> 
>                               Pekka


-- 
Hiroyuki Machida		machida@sm.sony.co.jp		
SSW Dept. HENC, Sony Corp.

  reply	other threads:[~2005-08-31 12:57 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-30  3:01 [RFC][FAT] diren scan profiling report Machida, Hiroyuki
2005-08-30  4:50 ` [PATCH][FAT] FAT dirent scan with hin take #2 Machida, Hiroyuki
2005-08-30  8:51   ` Pekka Enberg
2005-08-30  8:55   ` Pekka Enberg
2005-08-30  9:18     ` Vojtech Pavlik
2005-08-30 19:27   ` OGAWA Hirofumi
2005-08-31  1:43     ` OGAWA Hirofumi
2005-08-31  8:25     ` [PATCH][FAT] FAT dirent scan with hin take #3 Machida, Hiroyuki
2005-08-31 10:00       ` Pekka Enberg
2005-08-31 12:57         ` Machida, Hiroyuki [this message]
2005-08-31 13:51           ` Pekka Enberg
2005-08-31 13:53             ` Pekka Enberg
2005-08-31 10:03       ` Pekka Enberg
2005-08-31 13:27         ` Machida, Hiroyuki
2005-08-31 10:14       ` Pekka Enberg
2005-08-31 13:04         ` Machida, Hiroyuki
2005-08-31 13:52           ` Pekka Enberg
2005-08-31 16:41       ` OGAWA Hirofumi
2005-09-01  5:50         ` Machida, Hiroyuki
2005-09-01  7:45           ` Machida, Hiroyuki
2005-09-01 17:48           ` OGAWA Hirofumi
2005-09-14 18:59             ` Machida, Hiroyuki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4315A94E.3030901@sm.sony.co.jp \
    --to=machida@sm.sony.co.jp \
    --cc=hirofumi@mail.parknet.co.jp \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penberg@cs.helsinki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®