[U-Boot] [PATCH V4 08/10] dm: core: device: add function: dev_get_driver_ops()

Simon Glass sjg at chromium.org
Sun Apr 19 15:24:01 CEST 2015


Hi Przemyslaw,

On 15 April 2015 at 05:07, Przemyslaw Marczak <p.marczak at samsung.com> wrote:
> This commit extends the driver model device's API by function:
> - dev_get_driver_ops()
>
> And this function returns the device's driver's operations if given:
> - dev pointer, is non-NULL
> - dev->driver->ops pointer, is non-NULL
> in other case the, the NULL pointer is returned.
>
> Signed-off-by: Przemyslaw Marczak <p.marczak at samsung.com>
> Cc: Simon Glass <sjg at chromium.org>
> ---
> Changes V4:
> - new commit
> ---
>  drivers/core/device.c |  8 ++++++++
>  include/dm/device.h   | 11 +++++++++++
>  2 files changed, 19 insertions(+)
>
> diff --git a/drivers/core/device.c b/drivers/core/device.c
> index 80eb55b..d024abb 100644
> --- a/drivers/core/device.c
> +++ b/drivers/core/device.c
> @@ -499,6 +499,14 @@ ulong dev_get_driver_data(struct udevice *dev)
>         return dev->driver_data;
>  }
>
> +const void *dev_get_driver_ops(struct udevice *dev)
> +{
> +       if (!dev || !dev->driver->ops)

The second condition seems redundant to me. Perhaps it will become an
assert or other check one day. Anyway:

Acked-by: Simon Glass <sjg at chromium.org>


> +               return NULL;
> +
> +       return dev->driver->ops;
> +}
> +
>  enum uclass_id device_get_uclass_id(struct udevice *dev)
>  {
>         return dev->uclass->uc_drv->id;
> diff --git a/include/dm/device.h b/include/dm/device.h
> index ad002fe..049cb2f 100644
> --- a/include/dm/device.h
> +++ b/include/dm/device.h
> @@ -280,6 +280,17 @@ void *dev_get_uclass_priv(struct udevice *dev);
>   */
>  ulong dev_get_driver_data(struct udevice *dev);
>
> +/**
> + * dev_get_driver_ops() - get the device's driver's operations
> + *
> + * This checks that dev is not NULL, and returns the pointer to device's
> + * driver's operations.
> + *
> + * @dev:       Device to check
> + * @return void pointer to driver's operations or NULL for NULL-dev or NULL-ops
> + */
> +const void *dev_get_driver_ops(struct udevice *dev);
> +
>  /*
>   * device_get_uclass_id() - return the uclass ID of a device
>   *
> --
> 1.9.1
>

Regards,
Simon


More information about the U-Boot mailing list