aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRicardo Ribalda Delgado <ricardo.ribalda@gmail.com>2015-05-26 03:31:24 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2015-05-31 21:15:17 -0400
commite50e69d1ac4232af0b6890f16929bf5ceee81538 (patch)
treef1c64a18c3f5a38173d5ba06467bd3f2278583c4
parent36d4b29260753ad78b1ce4363145332c02519adc (diff)
base/platform: Continue on insert_resource() error
insert_resource() can fail when the resource added overlaps (partially or fully) with another. Device tree and AMBA devices may contain resources that overlap, so they could not call platform_device_add (see 02bbde7849e6 ('Revert "of: use platform_device_add"'))" On the other hand, device trees are released using platform_device_unregister(). This function calls platform_device_del(), which calls release_resource(), that crashes when the resource has not been added with with insert_resource. This was not an issue when the device tree could not be modified online, but this is not the case anymore. This patch let the flow continue when there is an insert error, after notifying the user with a dev_err(). r->parent is set to NULL, so platform_device_del() knows that the resource was not added, and therefore it should not be released. Acked-by: Rob Herring <robh@kernel.org> Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/base/platform.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 46a56f694cec..5a29387e5ff6 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -332,7 +332,7 @@ int platform_device_add(struct platform_device *pdev)
332 */ 332 */
333 ret = ida_simple_get(&platform_devid_ida, 0, 0, GFP_KERNEL); 333 ret = ida_simple_get(&platform_devid_ida, 0, 0, GFP_KERNEL);
334 if (ret < 0) 334 if (ret < 0)
335 goto err_out; 335 return ret;
336 pdev->id = ret; 336 pdev->id = ret;
337 pdev->id_auto = true; 337 pdev->id_auto = true;
338 dev_set_name(&pdev->dev, "%s.%d.auto", pdev->name, pdev->id); 338 dev_set_name(&pdev->dev, "%s.%d.auto", pdev->name, pdev->id);
@@ -340,7 +340,7 @@ int platform_device_add(struct platform_device *pdev)
340 } 340 }
341 341
342 for (i = 0; i < pdev->num_resources; i++) { 342 for (i = 0; i < pdev->num_resources; i++) {
343 struct resource *p, *r = &pdev->resource[i]; 343 struct resource *conflict, *p, *r = &pdev->resource[i];
344 unsigned long type = resource_type(r); 344 unsigned long type = resource_type(r);
345 345
346 if (r->name == NULL) 346 if (r->name == NULL)
@@ -357,11 +357,14 @@ int platform_device_add(struct platform_device *pdev)
357 p = &ioport_resource; 357 p = &ioport_resource;
358 } 358 }
359 359
360 if (insert_resource(p, r)) { 360 conflict = insert_resource_conflict(p, r);
361 dev_err(&pdev->dev, "failed to claim resource %d\n", i); 361 if (!conflict)
362 ret = -EBUSY; 362 continue;
363 goto failed; 363
364 } 364 dev_err(&pdev->dev,
365 "ignoring resource %pR (conflicts with %s %pR)\n",
366 r, conflict->name, conflict);
367 p->parent = NULL;
365 } 368 }
366 369
367 pr_debug("Registering platform device '%s'. Parent at %s\n", 370 pr_debug("Registering platform device '%s'. Parent at %s\n",
@@ -371,7 +374,7 @@ int platform_device_add(struct platform_device *pdev)
371 if (ret == 0) 374 if (ret == 0)
372 return ret; 375 return ret;
373 376
374 failed: 377 /* Failure path */
375 if (pdev->id_auto) { 378 if (pdev->id_auto) {
376 ida_simple_remove(&platform_devid_ida, pdev->id); 379 ida_simple_remove(&platform_devid_ida, pdev->id);
377 pdev->id = PLATFORM_DEVID_AUTO; 380 pdev->id = PLATFORM_DEVID_AUTO;
@@ -381,11 +384,11 @@ int platform_device_add(struct platform_device *pdev)
381 struct resource *r = &pdev->resource[i]; 384 struct resource *r = &pdev->resource[i];
382 unsigned long type = resource_type(r); 385 unsigned long type = resource_type(r);
383 386
384 if (type == IORESOURCE_MEM || type == IORESOURCE_IO) 387 if ((type == IORESOURCE_MEM || type == IORESOURCE_IO) &&
388 r->parent)
385 release_resource(r); 389 release_resource(r);
386 } 390 }
387 391
388 err_out:
389 return ret; 392 return ret;
390} 393}
391EXPORT_SYMBOL_GPL(platform_device_add); 394EXPORT_SYMBOL_GPL(platform_device_add);
@@ -414,7 +417,8 @@ void platform_device_del(struct platform_device *pdev)
414 struct resource *r = &pdev->resource[i]; 417 struct resource *r = &pdev->resource[i];
415 unsigned long type = resource_type(r); 418 unsigned long type = resource_type(r);
416 419
417 if (type == IORESOURCE_MEM || type == IORESOURCE_IO) 420 if ((type == IORESOURCE_MEM || type == IORESOURCE_IO) &&
421 r->parent)
418 release_resource(r); 422 release_resource(r);
419 } 423 }
420 } 424 }