Re: [PATCH v2 02/13] PCI: prevent duplicate slot names

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Matthew Wilcox
Date: Tuesday, September 9, 2008 - 6:07 am

On Tue, Sep 09, 2008 at 04:00:12AM -0600, Alex Chiang wrote:

Not quite true ... the Mth registered slot becomes N-(M-1).  With the
first '-' being a literal and the second being a minus sign ;-)


I would leave "the" in here.


I don't like the goto-loop style (yes, I know we do it elsewhere), and I
think we only need to krealloc inside the 'if' condition.  Something
like this, perhaps:

static char *make_slot_name(const char *name)
{
	char *new_name;
	int len, max, dup;

	new_name = kstrdup(name, GFP_KERNEL);
	if (!new_name)
		return NULL;

	/*
	 * Make sure we hit the realloc case the first time through the
	 * loop.  'len' will be strlen(name) + 3 at that point which is
	 * enough space for "name-X" and the trailing NUL.
	 */
	len = strlen(name) + 2;
	max = 1;
	dup = 1;

	for (;;) {
		struct kobject *dup_slot;
		dup_slot = kset_find_obj(pci_slots_kset, new_name);
		if (!dup_slot)
			break;
		kobject_put(dup_slot);
		if (dup == max) {
			len++;
			max *= 10;
			new_name = krealloc(new_name, len, GFP_KERNEL);
			if (!new_name)
				break;
		}
		sprintf(new_name, "%s-%d", name, dup++);
	}

	return new_name;
}
	


How about simply replacing this last line with:



I think you need to kfree() slot before you assign an ERR_PTR to it.
Actually, since the 'err' label does that, just make that:

	if (!slot_name) {
		err = -ENOMEM;
		goto err;
	}


Are you going to get enough information to debug problems with just this
WARN_ON?  And do we want to decline to renumber a slot to the same
number as an existing one?

Anyway, looks good, and I really like the name-change for this function.

-- 
Matthew Wilcox				Intel Open Source Technology Centre
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH v2 00/13] PCI: let the core manage slot names, Alex Chiang, (Tue Sep 9, 3:00 am)
[PATCH v2 02/13] PCI: prevent duplicate slot names, Alex Chiang, (Tue Sep 9, 3:00 am)
[PATCH v2 13/13] PCI: Hotplug core: remove 'name', Alex Chiang, (Tue Sep 9, 3:01 am)
Re: [PATCH v2 02/13] PCI: prevent duplicate slot names, Matthew Wilcox, (Tue Sep 9, 6:07 am)
Re: [PATCH v2 02/13] PCI: prevent duplicate slot names, Rolf Eike Beer, (Wed Sep 10, 7:58 am)
Re: [PATCH v2 02/13] PCI: prevent duplicate slot names, Kenji Kaneshige, (Wed Sep 10, 7:47 pm)
Re: [PATCH v2 02/13] PCI: prevent duplicate slot names, Alex Chiang, (Thu Sep 11, 3:37 am)
Re: [PATCH v2 02/13] PCI: prevent duplicate slot names, Alex Chiang, (Mon Sep 22, 2:38 pm)
Re: [PATCH v2 02/13] PCI: prevent duplicate slot names, Alex Chiang, (Mon Sep 22, 2:40 pm)
Re: [PATCH v2 02/13] PCI: prevent duplicate slot names, Matthew Wilcox, (Mon Sep 22, 3:42 pm)
Re: [PATCH v2 02/13] PCI: prevent duplicate slot names, Alex Chiang, (Mon Sep 22, 5:05 pm)