[PATCH linux 1/2] i2c: aspeed: Don't rename added devices

Joel Stanley joel at jms.id.au
Fri Feb 12 15:22:42 AEDT 2016


On Thu, Feb 11, 2016 at 12:00 PM, OpenBMC Patches
<openbmc-patches at stwcx.xyz> wrote:
> From: "Milton D. Miller II" <miltonm at us.ibm.com>
>
> Changing the name of a device with dev_set_name after device_add
> is not allowed.
>
> However, of_create_device takes a bus_id parameter that specifies
> the name of the platform device being added.
>
> This does mean the bus property has to be retrieved multiple times.
> Creation is skiped if there is trouble retrieving or formatting
> the name.

Ok, this approach looks alright.

> diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c
> index 5488233..ccb438f 100644
> --- a/drivers/i2c/busses/i2c-aspeed.c
> +++ b/drivers/i2c/busses/i2c-aspeed.c
> @@ -693,13 +693,6 @@ static int ast_i2c_probe_bus(struct platform_device *pdev)
>         if (ret)
>                 return -ENXIO;
>
> -       /*
> -        * Set a useful name derived from the bus number; the device tree
> -        * should provide us with one that corresponds to the hardware
> -        * numbering
> -        */
> -       dev_set_name(&pdev->dev, "i2c-%d", bus_num);
> -
>         bus->pclk = devm_clk_get(&pdev->dev, NULL);
>         if (IS_ERR(bus->pclk)) {
>                 dev_dbg(&pdev->dev, "clk_get failed\n");
> @@ -828,7 +821,26 @@ static int ast_i2c_probe_controller(struct platform_device *pdev)
>                         controller->irq);
>
>         for_each_child_of_node(pdev->dev.of_node, np) {
> -               of_platform_device_create(np, NULL, &pdev->dev);
> +               int ret;
> +               u32 bus_num;
> +               char bus_id[sizeof("i2c-12345")];

Clever, but I don't think it's kernel style. A constant will do.

> +
> +               /*
> +                * Set a useful name derived from the bus number; the device
> +                * tree should provide us with one that corresponds to the
> +                * hardware numbering.  If the property is missing the
> +                * probe would fail so just skip it here.
> +                */
> +
> +               ret = of_property_read_u32(np, "bus", &bus_num);
> +               if (ret)
> +                       continue;
> +
> +               ret = snprintf(bus_id, sizeof(bus_id), "i2c-%u", bus_num);
> +               if (ret >= sizeof(bus_id))
> +                       continue;

You should check for a negative value as well.

> +
> +               of_platform_device_create(np, bus_id, &pdev->dev);
>                 of_node_put(np);
>         }
>
> --
> 2.7.1
>
>
> _______________________________________________
> openbmc mailing list
> openbmc at lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/openbmc


More information about the openbmc mailing list