linux-renesas-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Neil Armstrong <narmstrong@baylibre.com>
Cc: Geert Uytterhoeven <geert+renesas@glider.be>,
	Andrzej Pietrasiewicz <andrzej.p@collabora.com>,
	Andrzej Hajda <a.hajda@samsung.com>,
	Laurent Pinchart <Laurent.pinchart@ideasonboard.com>,
	Jonas Karlman <jonas@kwiboo.se>,
	Jernej Skrabec <jernej.skrabec@siol.net>,
	David Airlie <airlied@linux.ie>, Daniel Vetter <daniel@ffwll.ch>,
	Sam Ravnborg <sam@ravnborg.org>,
	Emil Velikov <emil.velikov@collabora.com>,
	dri-devel@lists.freedesktop.org,
	linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drm/bridge: dumb-vga-dac: Fix dereferencing -ENODEV DDC channel
Date: Wed, 14 Aug 2019 07:39:20 -0700	[thread overview]
Message-ID: <20190814143920.GA30613@roeck-us.net> (raw)
In-Reply-To: <29ff3bfd-57ee-9c64-3706-555edc8b4675@baylibre.com>

On Tue, Aug 13, 2019 at 02:01:26PM +0200, Neil Armstrong wrote:
> Hi,
> 
> 
> On 13/08/2019 11:30, Geert Uytterhoeven wrote:
> > If the VGA connector has no DDC channel, an error pointer will be
> > dereferenced, e.g. on Salvator-XS:
> > 
> >     Unable to handle kernel NULL pointer dereference at virtual address 000000000000017d
> >     ...
> >     Call trace:
> >      sysfs_do_create_link_sd.isra.0+0x40/0x108
> >      sysfs_create_link+0x20/0x40
> >      drm_sysfs_connector_add+0xa8/0xc8
> >      drm_connector_register.part.3+0x54/0xb0
> >      drm_connector_register_all+0xb0/0xd0
> >      drm_modeset_register_all+0x54/0x88
> >      drm_dev_register+0x18c/0x1d8
> >      rcar_du_probe+0xe4/0x150
> >      ...
> > 
> > This happens because vga->ddc either contains a valid DDC channel
> > pointer, or -ENODEV, and drm_connector_init_with_ddc() expects a valid
> > DDC channel pointer, or NULL.
> > 
> > Fix this by resetting vga->ddc to NULL in case of -ENODEV, and replacing
> > the existing error checks by non-NULL checks.
> > This is similar to what the HDMI connector driver does.
> > 
> > Fixes: a4f9087e85de141e ("drm/bridge: dumb-vga-dac: Provide ddc symlink in connector sysfs directory")
> > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> > ---
> > An alternative would be to check if vga->ddc contains an error pointer,
> > and calling drm_connector_init() instead of
> > drm_connector_init_with_ddc(), like before.
> > ---
> >  drivers/gpu/drm/bridge/dumb-vga-dac.c | 7 ++++---
> >  1 file changed, 4 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/bridge/dumb-vga-dac.c b/drivers/gpu/drm/bridge/dumb-vga-dac.c
> > index 8ef6539ae78a6eb3..7aa789c358829b05 100644
> > --- a/drivers/gpu/drm/bridge/dumb-vga-dac.c
> > +++ b/drivers/gpu/drm/bridge/dumb-vga-dac.c
> > @@ -42,7 +42,7 @@ static int dumb_vga_get_modes(struct drm_connector *connector)
> >  	struct edid *edid;
> >  	int ret;
> >  
> > -	if (IS_ERR(vga->ddc))
> > +	if (!vga->ddc)
> >  		goto fallback;
> >  
> >  	edid = drm_get_edid(connector, vga->ddc);
> > @@ -84,7 +84,7 @@ dumb_vga_connector_detect(struct drm_connector *connector, bool force)
> >  	 * wire the DDC pins, or the I2C bus might not be working at
> >  	 * all.
> >  	 */
> > -	if (!IS_ERR(vga->ddc) && drm_probe_ddc(vga->ddc))
> > +	if (vga->ddc && drm_probe_ddc(vga->ddc))
> >  		return connector_status_connected;
> >  
> >  	return connector_status_unknown;
> > @@ -197,6 +197,7 @@ static int dumb_vga_probe(struct platform_device *pdev)
> >  		if (PTR_ERR(vga->ddc) == -ENODEV) {
> >  			dev_dbg(&pdev->dev,
> >  				"No i2c bus specified. Disabling EDID readout\n");
> > +			vga->ddc = NULL;
> >  		} else {
> >  			dev_err(&pdev->dev, "Couldn't retrieve i2c bus\n");
> >  			return PTR_ERR(vga->ddc);
> > @@ -218,7 +219,7 @@ static int dumb_vga_remove(struct platform_device *pdev)
> >  
> >  	drm_bridge_remove(&vga->bridge);
> >  
> > -	if (!IS_ERR(vga->ddc))
> > +	if (vga->ddc)
> >  		i2c_put_adapter(vga->ddc);
> >  
> >  	return 0;
> > 
> 
> Looks sane,
> 
> Reviewed-by: Neil Armstrong <narmstrong@baylibre.com>
> 
> Guenter, can you confirm it also fixes qemu:versatilepb ?
> 

Yes, it does.

Tested-by: Guenter Roeck <linux@roeck-us.net>

Guenter

  reply	other threads:[~2019-08-14 14:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-13  9:30 [PATCH] drm/bridge: dumb-vga-dac: Fix dereferencing -ENODEV DDC channel Geert Uytterhoeven
2019-08-13 12:01 ` Neil Armstrong
2019-08-14 14:39   ` Guenter Roeck [this message]
2019-08-14 14:46     ` Neil Armstrong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190814143920.GA30613@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=Laurent.pinchart@ideasonboard.com \
    --cc=a.hajda@samsung.com \
    --cc=airlied@linux.ie \
    --cc=andrzej.p@collabora.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=emil.velikov@collabora.com \
    --cc=geert+renesas@glider.be \
    --cc=jernej.skrabec@siol.net \
    --cc=jonas@kwiboo.se \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=narmstrong@baylibre.com \
    --cc=sam@ravnborg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).