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."
--