From 91cbd792c46c916ef196c5b7cd16ff592d2f3632 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 17 Sep 2014 09:02:38 -0600 Subject: dm: core: Allow device_bind() to used without CONFIG_OF_CONTROL The sequence number support in driver model requires device tree control. It should be skipped if CONFIG_OF_CONTROL is not defined, and should not require functions from fdtdec. Signed-off-by: Simon Glass --- drivers/core/device.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'drivers/core/device.c') diff --git a/drivers/core/device.c b/drivers/core/device.c index 166b0732ab..ef41a9be3e 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -106,13 +106,16 @@ int device_bind(struct udevice *parent, struct driver *drv, const char *name, * a 'requested' sequence, and will be resolved (and ->seq updated) * when the device is probed. */ - dev->req_seq = fdtdec_get_int(gd->fdt_blob, of_offset, "reg", -1); dev->seq = -1; +#ifdef CONFIG_OF_CONTROL + dev->req_seq = fdtdec_get_int(gd->fdt_blob, of_offset, "reg", -1); if (uc->uc_drv->name && of_offset != -1) { fdtdec_get_alias_seq(gd->fdt_blob, uc->uc_drv->name, of_offset, &dev->req_seq); } - +#else + dev->req_seq = -1; +#endif if (!dev->platdata && drv->platdata_auto_alloc_size) dev->flags |= DM_FLAG_ALLOC_PDATA; -- cgit v1.2.3 From cae025aab3e8ea8ad455cce8b0e4647401cdd091 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Thu, 18 Sep 2014 17:13:07 +0200 Subject: dm: avoid dev->req_seq overflow Since dev->req_seq value is initialized from "reg" property of fdt node, there is posibility, that address value contained in fdt is greater than INT_MAX, and then value in dev->req_seq is negative which led to probe() fail. This patch fix this problem by ensuring that req_seq is positive, unless it's one of errno codes. Signed-off-by: Robert Baldyga Acked-by: Simon Glass --- drivers/core/device.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers/core/device.c') diff --git a/drivers/core/device.c b/drivers/core/device.c index ef41a9be3e..32e80e82b5 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -109,6 +109,8 @@ int device_bind(struct udevice *parent, struct driver *drv, const char *name, dev->seq = -1; #ifdef CONFIG_OF_CONTROL dev->req_seq = fdtdec_get_int(gd->fdt_blob, of_offset, "reg", -1); + if (!IS_ERR_VALUE(dev->req_seq)) + dev->req_seq &= INT_MAX; if (uc->uc_drv->name && of_offset != -1) { fdtdec_get_alias_seq(gd->fdt_blob, uc->uc_drv->name, of_offset, &dev->req_seq); -- cgit v1.2.3