Skip to contentSkip to conversation

Bug in fs/kernfs/dir.c comment or code?

DISCUSSION Richard Cochran 2 participants 2 messages Mar 2, 2014 – Mar 3, 2014

lore
Share & tools
lore
#0 lore raw

I stumbled across this in fs/kernfs/dir.c:39.

	/* Reserve hash numbers 0, 1 and INT_MAX for magic directory entries */
	if (hash < 1)
		hash += 2;
	if (hash >= INT_MAX)
		hash = INT_MAX - 1;

Shouldn't that be (hash < 2), or is 1 not reserved?

Thanks,
Richard

#1 lore raw

(cc'ing Greg and Eric)

Quoted 9 lines · Richard Cochran

I stumbled across this in fs/kernfs/dir.c:39.

	/* Reserve hash numbers 0, 1 and INT_MAX for magic directory entries */
	if (hash < 1)
		hash += 2;
	if (hash >= INT_MAX)
		hash = INT_MAX - 1;

Shouldn't that be (hash < 2), or is 1 not reserved?

Looks like the code is wrong and the condition should be hash < 2. Difficult to trigger but an actual bug. The fix should probably be propagated to sysfs through -stable. Can you write up a patch?

Thanks.

Signature · 1 line
tejun