diff mbox

[1/3] drm: Tune up error message during format->bpp/cpp conversion

Message ID 1463058040-31828-2-git-send-email-imre.deak@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Imre Deak May 12, 2016, 1 p.m. UTC
Returning a 0 bpp/cpp value from these functions isn't ever valid. In
many cases it can also lead to a div-by-zero possibly at some later
point in time, so make sure we catch such errors as soon as possible via
louder error reporting.

CC: Dave Airlie <airlied@redhat.com>
Signed-off-by: Imre Deak <imre.deak@intel.com>
---
 drivers/gpu/drm/drm_crtc.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

Ville Syrjälä May 12, 2016, 1:10 p.m. UTC | #1
On Thu, May 12, 2016 at 04:00:38PM +0300, Imre Deak wrote:
> Returning a 0 bpp/cpp value from these functions isn't ever valid. In
> many cases it can also lead to a div-by-zero possibly at some later
> point in time, so make sure we catch such errors as soon as possible via
> louder error reporting.
> 
> CC: Dave Airlie <airlied@redhat.com>
> Signed-off-by: Imre Deak <imre.deak@intel.com>
> ---
>  drivers/gpu/drm/drm_crtc.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> index 70f9c68..3a32606 100644
> --- a/drivers/gpu/drm/drm_crtc.c
> +++ b/drivers/gpu/drm/drm_crtc.c
> @@ -5610,8 +5610,8 @@ void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
>  		*bpp = 32;
>  		break;
>  	default:
> -		DRM_DEBUG_KMS("unsupported pixel format %s\n",
> -			      drm_get_format_name(format));
> +		WARN(1, "unsupported pixel format %s\n",
> +		     drm_get_format_name(format));

NAK. This will happen every time drm_helper_mode_fill_fb_struct()
is called with a non-RGB format.

>  		*depth = 0;
>  		*bpp = 0;
>  		break;
> @@ -5666,8 +5666,12 @@ int drm_format_plane_cpp(uint32_t format, int plane)
>  	unsigned int depth;
>  	int bpp;
>  
> -	if (plane >= drm_format_num_planes(format))
> +	if (plane >= drm_format_num_planes(format)) {
> +		WARN(1, "invalid plane %d for format %s\n",
> +		     plane, drm_get_format_name(format));
> +

We have this check in many places. Should either convert all or none.

>  		return 0;
> +	}
>  
>  	switch (format) {
>  	case DRM_FORMAT_YUYV:
> -- 
> 2.5.0
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
Imre Deak May 12, 2016, 1:43 p.m. UTC | #2
On Thu, 2016-05-12 at 16:10 +0300, Ville Syrjälä wrote:
> On Thu, May 12, 2016 at 04:00:38PM +0300, Imre Deak wrote:
> > Returning a 0 bpp/cpp value from these functions isn't ever valid.
> > In
> > many cases it can also lead to a div-by-zero possibly at some later
> > point in time, so make sure we catch such errors as soon as
> > possible via
> > louder error reporting.
> > 
> > CC: Dave Airlie <airlied@redhat.com>
> > Signed-off-by: Imre Deak <imre.deak@intel.com>
> > ---
> >  drivers/gpu/drm/drm_crtc.c | 10 +++++++---
> >  1 file changed, 7 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/drm_crtc.c
> > b/drivers/gpu/drm/drm_crtc.c
> > index 70f9c68..3a32606 100644
> > --- a/drivers/gpu/drm/drm_crtc.c
> > +++ b/drivers/gpu/drm/drm_crtc.c
> > @@ -5610,8 +5610,8 @@ void drm_fb_get_bpp_depth(uint32_t format,
> > unsigned int *depth,
> >  		*bpp = 32;
> >  		break;
> >  	default:
> > -		DRM_DEBUG_KMS("unsupported pixel format %s\n",
> > -			      drm_get_format_name(format));
> > +		WARN(1, "unsupported pixel format %s\n",
> > +		     drm_get_format_name(format));
> 
> NAK. This will happen every time drm_helper_mode_fill_fb_struct()
> is called with a non-RGB format.

Yep, missed that. So how about handling here those formats explicitly,
and emitting a warning only for truly unsupported formats?

> >  		*depth = 0;
> >  		*bpp = 0;
> >  		break;
> > @@ -5666,8 +5666,12 @@ int drm_format_plane_cpp(uint32_t format,
> > int plane)
> >  	unsigned int depth;
> >  	int bpp;
> >  
> > -	if (plane >= drm_format_num_planes(format))
> > +	if (plane >= drm_format_num_planes(format)) {
> > +		WARN(1, "invalid plane %d for format %s\n",
> > +		     plane, drm_get_format_name(format));
> > +
> 
> We have this check in many places. Should either convert all or none.

Ok, I can also change drm_format_plane_width()
and drm_format_plane_height(). Couldn't spot any other places.

> >  		return 0;
> > +	}
> >  
> >  	switch (format) {
> >  	case DRM_FORMAT_YUYV:
> > -- 
> > 2.5.0
> > 
> > _______________________________________________
> > dri-devel mailing list
> > dri-devel@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/dri-devel
>
Ville Syrjälä May 12, 2016, 1:52 p.m. UTC | #3
On Thu, May 12, 2016 at 04:43:05PM +0300, Imre Deak wrote:
> On Thu, 2016-05-12 at 16:10 +0300, Ville Syrjälä wrote:
> > On Thu, May 12, 2016 at 04:00:38PM +0300, Imre Deak wrote:
> > > Returning a 0 bpp/cpp value from these functions isn't ever valid.
> > > In
> > > many cases it can also lead to a div-by-zero possibly at some later
> > > point in time, so make sure we catch such errors as soon as
> > > possible via
> > > louder error reporting.
> > > 
> > > CC: Dave Airlie <airlied@redhat.com>
> > > Signed-off-by: Imre Deak <imre.deak@intel.com>
> > > ---
> > >  drivers/gpu/drm/drm_crtc.c | 10 +++++++---
> > >  1 file changed, 7 insertions(+), 3 deletions(-)
> > > 
> > > diff --git a/drivers/gpu/drm/drm_crtc.c
> > > b/drivers/gpu/drm/drm_crtc.c
> > > index 70f9c68..3a32606 100644
> > > --- a/drivers/gpu/drm/drm_crtc.c
> > > +++ b/drivers/gpu/drm/drm_crtc.c
> > > @@ -5610,8 +5610,8 @@ void drm_fb_get_bpp_depth(uint32_t format,
> > > unsigned int *depth,
> > >  		*bpp = 32;
> > >  		break;
> > >  	default:
> > > -		DRM_DEBUG_KMS("unsupported pixel format %s\n",
> > > -			      drm_get_format_name(format));
> > > +		WARN(1, "unsupported pixel format %s\n",
> > > +		     drm_get_format_name(format));
> > 
> > NAK. This will happen every time drm_helper_mode_fill_fb_struct()
> > is called with a non-RGB format.
> 
> Yep, missed that. So how about handling here those formats explicitly,
> and emitting a warning only for truly unsupported formats?

More work to keep this list updated, and it wouldn't prevent any
div-by-zero with those formats. So I don't really see a point in that.

> 
> > >  		*depth = 0;
> > >  		*bpp = 0;
> > >  		break;
> > > @@ -5666,8 +5666,12 @@ int drm_format_plane_cpp(uint32_t format,
> > > int plane)
> > >  	unsigned int depth;
> > >  	int bpp;
> > >  
> > > -	if (plane >= drm_format_num_planes(format))
> > > +	if (plane >= drm_format_num_planes(format)) {
> > > +		WARN(1, "invalid plane %d for format %s\n",
> > > +		     plane, drm_get_format_name(format));
> > > +
> > 
> > We have this check in many places. Should either convert all or none.
> 
> Ok, I can also change drm_format_plane_width()
> and drm_format_plane_height(). Couldn't spot any other places.

I thought we might have more. I guess not.

> 
> > >  		return 0;
> > > +	}
> > >  
> > >  	switch (format) {
> > >  	case DRM_FORMAT_YUYV:
> > > -- 
> > > 2.5.0
> > > 
> > > _______________________________________________
> > > dri-devel mailing list
> > > dri-devel@lists.freedesktop.org
> > > https://lists.freedesktop.org/mailman/listinfo/dri-devel
> >
Imre Deak May 12, 2016, 2 p.m. UTC | #4
On Thu, 2016-05-12 at 16:52 +0300, Ville Syrjälä wrote:
> On Thu, May 12, 2016 at 04:43:05PM +0300, Imre Deak wrote:
> > On Thu, 2016-05-12 at 16:10 +0300, Ville Syrjälä wrote:
> > > On Thu, May 12, 2016 at 04:00:38PM +0300, Imre Deak wrote:
> > > > Returning a 0 bpp/cpp value from these functions isn't ever
> > > > valid.
> > > > In
> > > > many cases it can also lead to a div-by-zero possibly at some
> > > > later
> > > > point in time, so make sure we catch such errors as soon as
> > > > possible via
> > > > louder error reporting.
> > > > 
> > > > CC: Dave Airlie <airlied@redhat.com>
> > > > Signed-off-by: Imre Deak <imre.deak@intel.com>
> > > > ---
> > > >  drivers/gpu/drm/drm_crtc.c | 10 +++++++---
> > > >  1 file changed, 7 insertions(+), 3 deletions(-)
> > > > 
> > > > diff --git a/drivers/gpu/drm/drm_crtc.c
> > > > b/drivers/gpu/drm/drm_crtc.c
> > > > index 70f9c68..3a32606 100644
> > > > --- a/drivers/gpu/drm/drm_crtc.c
> > > > +++ b/drivers/gpu/drm/drm_crtc.c
> > > > @@ -5610,8 +5610,8 @@ void drm_fb_get_bpp_depth(uint32_t
> > > > format,
> > > > unsigned int *depth,
> > > >  		*bpp = 32;
> > > >  		break;
> > > >  	default:
> > > > -		DRM_DEBUG_KMS("unsupported pixel format %s\n",
> > > > -			      drm_get_format_name(format));
> > > > +		WARN(1, "unsupported pixel format %s\n",
> > > > +		     drm_get_format_name(format));
> > > 
> > > NAK. This will happen every time drm_helper_mode_fill_fb_struct()
> > > is called with a non-RGB format.
> > 
> > Yep, missed that. So how about handling here those formats
> > explicitly,
> > and emitting a warning only for truly unsupported formats?
> 
> More work to keep this list updated, and it wouldn't prevent any
> div-by-zero with those formats. So I don't really see a point in
> that.

It would avoid the incorrect 'unsupported pixel format' message for
those.

> > 
> > > >  		*depth = 0;
> > > >  		*bpp = 0;
> > > >  		break;
> > > > @@ -5666,8 +5666,12 @@ int drm_format_plane_cpp(uint32_t
> > > > format,
> > > > int plane)
> > > >  	unsigned int depth;
> > > >  	int bpp;
> > > >  
> > > > -	if (plane >= drm_format_num_planes(format))
> > > > +	if (plane >= drm_format_num_planes(format)) {
> > > > +		WARN(1, "invalid plane %d for format %s\n",
> > > > +		     plane, drm_get_format_name(format));
> > > > +
> > > 
> > > We have this check in many places. Should either convert all or
> > > none.
> > 
> > Ok, I can also change drm_format_plane_width()
> > and drm_format_plane_height(). Couldn't spot any other places.
> 
> I thought we might have more. I guess not.
> 
> > 
> > > >  		return 0;
> > > > +	}
> > > >  
> > > >  	switch (format) {
> > > >  	case DRM_FORMAT_YUYV:
> > > > -- 
> > > > 2.5.0
> > > > 
> > > > _______________________________________________
> > > > dri-devel mailing list
> > > > dri-devel@lists.freedesktop.org
> > > > https://lists.freedesktop.org/mailman/listinfo/dri-devel
> > > 
>
Daniel Vetter May 12, 2016, 2:02 p.m. UTC | #5
On Thu, May 12, 2016 at 05:00:06PM +0300, Imre Deak wrote:
> On Thu, 2016-05-12 at 16:52 +0300, Ville Syrjälä wrote:
> > On Thu, May 12, 2016 at 04:43:05PM +0300, Imre Deak wrote:
> > > On Thu, 2016-05-12 at 16:10 +0300, Ville Syrjälä wrote:
> > > > On Thu, May 12, 2016 at 04:00:38PM +0300, Imre Deak wrote:
> > > > > Returning a 0 bpp/cpp value from these functions isn't ever
> > > > > valid.
> > > > > In
> > > > > many cases it can also lead to a div-by-zero possibly at some
> > > > > later
> > > > > point in time, so make sure we catch such errors as soon as
> > > > > possible via
> > > > > louder error reporting.
> > > > > 
> > > > > CC: Dave Airlie <airlied@redhat.com>
> > > > > Signed-off-by: Imre Deak <imre.deak@intel.com>
> > > > > ---
> > > > >  drivers/gpu/drm/drm_crtc.c | 10 +++++++---
> > > > >  1 file changed, 7 insertions(+), 3 deletions(-)
> > > > > 
> > > > > diff --git a/drivers/gpu/drm/drm_crtc.c
> > > > > b/drivers/gpu/drm/drm_crtc.c
> > > > > index 70f9c68..3a32606 100644
> > > > > --- a/drivers/gpu/drm/drm_crtc.c
> > > > > +++ b/drivers/gpu/drm/drm_crtc.c
> > > > > @@ -5610,8 +5610,8 @@ void drm_fb_get_bpp_depth(uint32_t
> > > > > format,
> > > > > unsigned int *depth,
> > > > >  		*bpp = 32;
> > > > >  		break;
> > > > >  	default:
> > > > > -		DRM_DEBUG_KMS("unsupported pixel format %s\n",
> > > > > -			      drm_get_format_name(format));
> > > > > +		WARN(1, "unsupported pixel format %s\n",
> > > > > +		     drm_get_format_name(format));
> > > > 
> > > > NAK. This will happen every time drm_helper_mode_fill_fb_struct()
> > > > is called with a non-RGB format.
> > > 
> > > Yep, missed that. So how about handling here those formats
> > > explicitly,
> > > and emitting a warning only for truly unsupported formats?
> > 
> > More work to keep this list updated, and it wouldn't prevent any
> > div-by-zero with those formats. So I don't really see a point in
> > that.
> 
> It would avoid the incorrect 'unsupported pixel format' message for
> those.

If that's the entire concern, delete it. New drivers shouldn't use these
functions any more anyway.
-Daniel
diff mbox

Patch

diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 70f9c68..3a32606 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -5610,8 +5610,8 @@  void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
 		*bpp = 32;
 		break;
 	default:
-		DRM_DEBUG_KMS("unsupported pixel format %s\n",
-			      drm_get_format_name(format));
+		WARN(1, "unsupported pixel format %s\n",
+		     drm_get_format_name(format));
 		*depth = 0;
 		*bpp = 0;
 		break;
@@ -5666,8 +5666,12 @@  int drm_format_plane_cpp(uint32_t format, int plane)
 	unsigned int depth;
 	int bpp;
 
-	if (plane >= drm_format_num_planes(format))
+	if (plane >= drm_format_num_planes(format)) {
+		WARN(1, "invalid plane %d for format %s\n",
+		     plane, drm_get_format_name(format));
+
 		return 0;
+	}
 
 	switch (format) {
 	case DRM_FORMAT_YUYV: