diff mbox series

[v2,1/3] drm/rect: Add DRM_RECT_INIT() macro

Message ID 20220612161248.271590-2-jose.exposito89@gmail.com (mailing list archive)
State New, archived
Headers show
Series KUnit tests for drm_format_helper | expand

Commit Message

José Expósito June 12, 2022, 4:12 p.m. UTC
Add a helper macro to initialize a rectangle from x, y, width and
height information.

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
---
 include/drm/drm_rect.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Jani Nikula June 13, 2022, 7:53 a.m. UTC | #1
On Sun, 12 Jun 2022, José Expósito <jose.exposito89@gmail.com> wrote:
> Add a helper macro to initialize a rectangle from x, y, width and
> height information.
>
> Signed-off-by: José Expósito <jose.exposito89@gmail.com>
> ---
>  include/drm/drm_rect.h | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
>
> diff --git a/include/drm/drm_rect.h b/include/drm/drm_rect.h
> index 6f6e19bd4dac..945696323c69 100644
> --- a/include/drm/drm_rect.h
> +++ b/include/drm/drm_rect.h
> @@ -47,6 +47,18 @@ struct drm_rect {
>  	int x1, y1, x2, y2;
>  };
>  
> +/**
> + * DRM_RECT_INIT - initialize a rectangle from x/y/w/h
> + * @x: x coordinate
> + * @y: y coordinate
> + * @w: width
> + * @h: height
> + *
> + * RETURNS:
> + * A new rectangle of the specified size.
> + */
> +#define DRM_RECT_INIT(x, y, w, h) { (x), (y), (x) + (w), (y) + (h) }

Please use designated initializers.

It might help type safety if it also contained a (struct drm_rect) cast.

BR,
Jani.


> +
>  /**
>   * DRM_RECT_FMT - printf string for &struct drm_rect
>   */
José Expósito June 13, 2022, 5:19 p.m. UTC | #2
On Mon, Jun 13, 2022 at 10:53:57AM +0300, Jani Nikula wrote:
> On Sun, 12 Jun 2022, José Expósito <jose.exposito89@gmail.com> wrote:
> > Add a helper macro to initialize a rectangle from x, y, width and
> > height information.
> >
> > Signed-off-by: José Expósito <jose.exposito89@gmail.com>
> > ---
> >  include/drm/drm_rect.h | 12 ++++++++++++
> >  1 file changed, 12 insertions(+)
> >
> > diff --git a/include/drm/drm_rect.h b/include/drm/drm_rect.h
> > index 6f6e19bd4dac..945696323c69 100644
> > --- a/include/drm/drm_rect.h
> > +++ b/include/drm/drm_rect.h
> > @@ -47,6 +47,18 @@ struct drm_rect {
> >  	int x1, y1, x2, y2;
> >  };
> >  
> > +/**
> > + * DRM_RECT_INIT - initialize a rectangle from x/y/w/h
> > + * @x: x coordinate
> > + * @y: y coordinate
> > + * @w: width
> > + * @h: height
> > + *
> > + * RETURNS:
> > + * A new rectangle of the specified size.
> > + */
> > +#define DRM_RECT_INIT(x, y, w, h) { (x), (y), (x) + (w), (y) + (h) }
> 
> Please use designated initializers.
> 
> It might help type safety if it also contained a (struct drm_rect) cast.

Thanks a lot for your review Jani, just emailed v3 with your suggested
changes.

Jose
 
> BR,
> Jani.
> 
> 
> > +
> >  /**
> >   * DRM_RECT_FMT - printf string for &struct drm_rect
> >   */
> 
> -- 
> Jani Nikula, Intel Open Source Graphics Center
diff mbox series

Patch

diff --git a/include/drm/drm_rect.h b/include/drm/drm_rect.h
index 6f6e19bd4dac..945696323c69 100644
--- a/include/drm/drm_rect.h
+++ b/include/drm/drm_rect.h
@@ -47,6 +47,18 @@  struct drm_rect {
 	int x1, y1, x2, y2;
 };
 
+/**
+ * DRM_RECT_INIT - initialize a rectangle from x/y/w/h
+ * @x: x coordinate
+ * @y: y coordinate
+ * @w: width
+ * @h: height
+ *
+ * RETURNS:
+ * A new rectangle of the specified size.
+ */
+#define DRM_RECT_INIT(x, y, w, h) { (x), (y), (x) + (w), (y) + (h) }
+
 /**
  * DRM_RECT_FMT - printf string for &struct drm_rect
  */