Commit a636ee7fb35b731ba2b331f6294e809bb6be09c8

Authored by Paul Mundt
1 parent 57d54889cd

driver core: Early dev_name() support.

Presently early platform devices suffer from the fact they are unable to
use dev_xxx() calls early on due to dev_name() and others being
unavailable at the time ->probe() is called.

This implements early init_name construction from the matched name/id
pair following the semantics of the late device/driver match. As a
result, matched IDs (inclusive of requested ones) are preserved when the
handoff from the early platform code happens at kobject initialization
time.

Since we still require kmalloc slabs to be available at this point, using
kstrdup() for establishing the init_name works fine. This subsequently
needs to be tested from dev_name() prior to the init_name being cleared
by the driver core. We don't kfree() since others will already have a
handle on the string long before the kobject initialization takes place.

This is also needed to permit drivers to use the clock framework early,
without having to manually construct their own device IDs from the match
id/name pair locally (needed by the early console and timer code on sh
and arm).

Signed-off-by: Paul Mundt <lethal@linux-sh.org>
Acked-by: Greg Kroah-Hartman <gregkh@suse.de>

Showing 2 changed files with 23 additions and 0 deletions Side-by-side Diff

drivers/base/platform.c
... ... @@ -1239,6 +1239,25 @@
1239 1239 }
1240 1240  
1241 1241 if (match) {
  1242 + /*
  1243 + * Set up a sensible init_name to enable
  1244 + * dev_name() and others to be used before the
  1245 + * rest of the driver core is initialized.
  1246 + */
  1247 + if (!match->dev.init_name) {
  1248 + char buf[32];
  1249 +
  1250 + if (match->id != -1)
  1251 + snprintf(buf, sizeof(buf), "%s.%d",
  1252 + match->name, match->id);
  1253 + else
  1254 + snprintf(buf, sizeof(buf), "%s",
  1255 + match->name);
  1256 +
  1257 + match->dev.init_name = kstrdup(buf, GFP_KERNEL);
  1258 + if (!match->dev.init_name)
  1259 + return -ENOMEM;
  1260 + }
1242 1261 if (epdrv->pdrv->probe(match))
1243 1262 pr_warning("%s: unable to probe %s early.\n",
1244 1263 class_str, match->name);
include/linux/device.h
... ... @@ -451,6 +451,10 @@
451 451  
452 452 static inline const char *dev_name(const struct device *dev)
453 453 {
  454 + /* Use the init name until the kobject becomes available */
  455 + if (dev->init_name)
  456 + return dev->init_name;
  457 +
454 458 return kobject_name(&dev->kobj);
455 459 }
456 460