> Subject: [PATCH v6 2/5] drm/atomic: Add error_code element in atomic_state
> 
> Now that a proper error code will be returned to the user on any failure in
> atomic_ioctl() via struct drm_mode_atomic, add a new element error_code in
> the struct drm_atomic_state so as to hold the error code during the
> atomic_check() and atomic_commit() phases.
> New function added to print the error message and fill the struct err_code
> with proper error message and error code.
> 
> v5: Add a function for printing the error message and filling err_code
>     struct
> v6: Replace drm_err with drm_dbg_atomic print
> 
> Signed-off-by: Arun R Murthy <[email protected]>
> ---
>  drivers/gpu/drm/drm_atomic.c | 31 +++++++++++++++++++++++++++++++
>  include/drm/drm_atomic.h     | 10 ++++++++++
>  2 files changed, 41 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index
> 0fda567c390057b10bce691d9ddc11308088d92e..52eacb5a109d1c0f5b017e
> 552d9f5169f8d8fea5 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -1897,6 +1897,37 @@ void drm_state_dump(struct drm_device *dev,
> struct drm_printer *p)  }  EXPORT_SYMBOL(drm_state_dump);
> 
> +/**
> + * drm_mode_atomic_add_error_msg - function to add error code and error
> +string
> + *
> + * @err_code: pointer to struct drm_mode_atomic_err_code that stores the
> failure
> + *         reason
> + * @failure_code: failure code in enum drm_mode_atomic_failure_codes
> + * @failure_string: failure reason string message
> + *
> + * Returns: void
> + */
> +void drm_mode_atomic_add_error_msg(struct drm_mode_atomic_err_code
> *err_code,
> +                                __u64 failure_code, const char *format, ...) 
> {
> +     struct drm_atomic_state *state = container_of(err_code,
> +                                                   struct drm_atomic_state,
> +                                                   error_code);
> +     va_list varg;
> +     char *failure_string;
> +
> +     err_code->failure_code = failure_code;
> +
> +     va_start(varg, format);
> +     failure_string = kvasprintf(GFP_ATOMIC, format, varg);
> +
> +     drm_dbg_atomic(state->dev, "%s\n", failure_string);

In the next patches we endup changing the dbg message format from
"Commit failed: <failure reason>" to just "<failure reason>"
Maybe this should be "Commit failed: %s"

Regards,
Suraj Kandpal

> +     strscpy_pad(err_code->failure_string, failure_string,
> +                 sizeof(err_code->failure_string));
> +     va_end(varg);
> +}
> +EXPORT_SYMBOL(drm_mode_atomic_add_error_msg);
> +
>  #ifdef CONFIG_DEBUG_FS
>  static int drm_state_info(struct seq_file *m, void *data)  { diff --git
> a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h index
> c8ab2163bf658cd06b12a8dabada7c088a328654..205ce418da22f8cbe10ea3
> 53c62471dbb41ae2e8 100644
> --- a/include/drm/drm_atomic.h
> +++ b/include/drm/drm_atomic.h
> @@ -589,6 +589,13 @@ struct drm_atomic_state {
>        * commit without blocking.
>        */
>       struct work_struct commit_work;
> +
> +     /* @error_code: pointer to struct holding failure reason and string
> +      *
> +      * struct to convey user readable error to the user.
> +      * Error codes defined in enum drm_mode_atomic_failure_flags
> +      */
> +     struct drm_mode_atomic_err_code error_code;
>  };
> 
>  void __drm_crtc_commit_free(struct kref *kref); @@ -1259,5 +1266,8 @@
> drm_atomic_get_old_bridge_state(const struct drm_atomic_state *state,
> struct drm_bridge_state *  drm_atomic_get_new_bridge_state(const struct
> drm_atomic_state *state,
>                               struct drm_bridge *bridge);
> +__printf(3, 4)
> +void drm_mode_atomic_add_error_msg(struct drm_mode_atomic_err_code
> *err_code,
> +                                __u64 failure_code, const char *format, ...);
> 
>  #endif /* DRM_ATOMIC_H_ */
> 
> --
> 2.25.1

Reply via email to