linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/bridge: imx: fix potential NULL pointer dereference in imx8qxp_ldb_parse_dt_companion()
@ 2023-08-28 16:55 Zhang Shurong
  2023-08-28 17:28 ` Laurent Pinchart
  0 siblings, 1 reply; 5+ messages in thread
From: Zhang Shurong @ 2023-08-28 16:55 UTC (permalink / raw)
  To: victor.liu
  Cc: andrzej.hajda, neil.armstrong, rfoss, Laurent.pinchart, jonas,
	jernej.skrabec, airlied, daniel, shawnguo, s.hauer, kernel,
	festevam, linux-imx, dri-devel, linux-arm-kernel, linux-kernel,
	Zhang Shurong

of_match_device() may fail and returns a NULL pointer.

Fix this by checking the return value of of_match_device().

Fixes: 3818715f62b4 ("drm/bridge: imx: Add LDB support for i.MX8qxp")
Signed-off-by: Zhang Shurong <zhang_shurong@foxmail.com>
---
 drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c b/drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c
index 7984da9c0a35..d272f35c8eac 100644
--- a/drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c
+++ b/drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c
@@ -488,6 +488,8 @@ static int imx8qxp_ldb_parse_dt_companion(struct imx8qxp_ldb *imx8qxp_ldb)
 	 * string.
 	 */
 	match = of_match_device(dev->driver->of_match_table, dev);
+	if (!match)
+		return -ENODEV;
 	if (!of_device_is_compatible(companion, match->compatible)) {
 		DRM_DEV_ERROR(dev, "companion LDB is incompatible\n");
 		ret = -ENXIO;
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] drm/bridge: imx: fix potential NULL pointer dereference in imx8qxp_ldb_parse_dt_companion()
  2023-08-28 16:55 [PATCH] drm/bridge: imx: fix potential NULL pointer dereference in imx8qxp_ldb_parse_dt_companion() Zhang Shurong
@ 2023-08-28 17:28 ` Laurent Pinchart
  2023-08-28 18:01   ` Zhang Shurong
  0 siblings, 1 reply; 5+ messages in thread
From: Laurent Pinchart @ 2023-08-28 17:28 UTC (permalink / raw)
  To: Zhang Shurong
  Cc: victor.liu, andrzej.hajda, neil.armstrong, rfoss, jonas,
	jernej.skrabec, airlied, daniel, shawnguo, s.hauer, kernel,
	festevam, linux-imx, dri-devel, linux-arm-kernel, linux-kernel

Hi Zhang,

Thank you for the patch.

On Tue, Aug 29, 2023 at 12:55:01AM +0800, Zhang Shurong wrote:
> of_match_device() may fail and returns a NULL pointer.

How can it return a NULL pointer here ?

> Fix this by checking the return value of of_match_device().
> 
> Fixes: 3818715f62b4 ("drm/bridge: imx: Add LDB support for i.MX8qxp")
> Signed-off-by: Zhang Shurong <zhang_shurong@foxmail.com>
> ---
>  drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c b/drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c
> index 7984da9c0a35..d272f35c8eac 100644
> --- a/drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c
> +++ b/drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c
> @@ -488,6 +488,8 @@ static int imx8qxp_ldb_parse_dt_companion(struct imx8qxp_ldb *imx8qxp_ldb)
>  	 * string.
>  	 */
>  	match = of_match_device(dev->driver->of_match_table, dev);
> +	if (!match)
> +		return -ENODEV;
>  	if (!of_device_is_compatible(companion, match->compatible)) {
>  		DRM_DEV_ERROR(dev, "companion LDB is incompatible\n");
>  		ret = -ENXIO;

-- 
Regards,

Laurent Pinchart

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] drm/bridge: imx: fix potential NULL pointer dereference in imx8qxp_ldb_parse_dt_companion()
  2023-08-28 17:28 ` Laurent Pinchart
@ 2023-08-28 18:01   ` Zhang Shurong
  2023-08-28 18:37     ` Laurent Pinchart
  0 siblings, 1 reply; 5+ messages in thread
From: Zhang Shurong @ 2023-08-28 18:01 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: victor.liu, andrzej.hajda, neil.armstrong, rfoss, jonas,
	jernej.skrabec, airlied, daniel, shawnguo, s.hauer, kernel,
	festevam, linux-imx, dri-devel, linux-arm-kernel, linux-kernel

在 2023年8月29日星期二 CST 上午1:28:22,Laurent Pinchart 写道:
> Hi Zhang,
> 
> Thank you for the patch.
> 
> On Tue, Aug 29, 2023 at 12:55:01AM +0800, Zhang Shurong wrote:
> > of_match_device() may fail and returns a NULL pointer.
> 
> How can it return a NULL pointer here ?
> 
> > Fix this by checking the return value of of_match_device().
> > 
> > Fixes: 3818715f62b4 ("drm/bridge: imx: Add LDB support for i.MX8qxp")
> > Signed-off-by: Zhang Shurong <zhang_shurong@foxmail.com>
> > ---
> > 
> >  drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c
> > b/drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c index
> > 7984da9c0a35..d272f35c8eac 100644
> > --- a/drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c
> > +++ b/drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c
> > @@ -488,6 +488,8 @@ static int imx8qxp_ldb_parse_dt_companion(struct
> > imx8qxp_ldb *imx8qxp_ldb)> 
> >  	 * string.
> >  	 */
> >  	
> >  	match = of_match_device(dev->driver->of_match_table, dev);
> > 
> > +	if (!match)
> > +		return -ENODEV;
> > 
> >  	if (!of_device_is_compatible(companion, match->compatible)) {
> >  	
> >  		DRM_DEV_ERROR(dev, "companion LDB is incompatible\n");
> >  		ret = -ENXIO;
I think we can make it happen by designing the platform device in a way that 
its name aligns with that of the driver. In such a scenario, when the driver 
is probed, the of_match_device function will return null. You can verify this 
functionality by reviewing the following function:

static int platform_match(struct device *dev, struct device_driver *drv)




_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] drm/bridge: imx: fix potential NULL pointer dereference in imx8qxp_ldb_parse_dt_companion()
  2023-08-28 18:01   ` Zhang Shurong
@ 2023-08-28 18:37     ` Laurent Pinchart
  2023-08-29  2:28       ` Ying Liu
  0 siblings, 1 reply; 5+ messages in thread
From: Laurent Pinchart @ 2023-08-28 18:37 UTC (permalink / raw)
  To: Zhang Shurong
  Cc: victor.liu, andrzej.hajda, neil.armstrong, rfoss, jonas,
	jernej.skrabec, airlied, daniel, shawnguo, s.hauer, kernel,
	festevam, linux-imx, dri-devel, linux-arm-kernel, linux-kernel

On Tue, Aug 29, 2023 at 02:01:25AM +0800, Zhang Shurong wrote:
> 在 2023年8月29日星期二 CST 上午1:28:22,Laurent Pinchart 写道:
> > Hi Zhang,
> > 
> > Thank you for the patch.
> > 
> > On Tue, Aug 29, 2023 at 12:55:01AM +0800, Zhang Shurong wrote:
> > > of_match_device() may fail and returns a NULL pointer.
> > 
> > How can it return a NULL pointer here ?
> > 
> > > Fix this by checking the return value of of_match_device().
> > > 
> > > Fixes: 3818715f62b4 ("drm/bridge: imx: Add LDB support for i.MX8qxp")
> > > Signed-off-by: Zhang Shurong <zhang_shurong@foxmail.com>
> > > ---
> > > 
> > >  drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c | 2 ++
> > >  1 file changed, 2 insertions(+)
> > > 
> > > diff --git a/drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c
> > > b/drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c index
> > > 7984da9c0a35..d272f35c8eac 100644
> > > --- a/drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c
> > > +++ b/drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c
> > > @@ -488,6 +488,8 @@ static int imx8qxp_ldb_parse_dt_companion(struct imx8qxp_ldb *imx8qxp_ldb)
> > >  	 * string.
> > >  	 */
> > >  	match = of_match_device(dev->driver->of_match_table, dev);
> > > +	if (!match)
> > > +		return -ENODEV;
> > >  	if (!of_device_is_compatible(companion, match->compatible)) {
> > >  		DRM_DEV_ERROR(dev, "companion LDB is incompatible\n");
> > >  		ret = -ENXIO;
>
> I think we can make it happen by designing the platform device in a way that 
> its name aligns with that of the driver. In such a scenario, when the driver 
> is probed, the of_match_device function will return null. You can verify this 
> functionality by reviewing the following function:
> 
> static int platform_match(struct device *dev, struct device_driver *drv)

This particular device is found in OF-based systems only, and only
instantiated through DT. You can create a platform_device manually that
may match this driver, but that would be a made-up situation, not
something that can happen in practice.

-- 
Regards,

Laurent Pinchart

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH] drm/bridge: imx: fix potential NULL pointer dereference in imx8qxp_ldb_parse_dt_companion()
  2023-08-28 18:37     ` Laurent Pinchart
@ 2023-08-29  2:28       ` Ying Liu
  0 siblings, 0 replies; 5+ messages in thread
From: Ying Liu @ 2023-08-29  2:28 UTC (permalink / raw)
  To: Laurent Pinchart, Zhang Shurong
  Cc: andrzej.hajda@intel.com, neil.armstrong@linaro.org,
	rfoss@kernel.org, jonas@kwiboo.se, jernej.skrabec@gmail.com,
	airlied@gmail.com, daniel@ffwll.ch, shawnguo@kernel.org,
	s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com,
	dl-linux-imx, dri-devel@lists.freedesktop.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org

On Tuesday, August 29, 2023 2:38 AM Laurent Pinchart <laurent.pinchart@ideasonboard.com> wrote:
> On Tue, Aug 29, 2023 at 02:01:25AM +0800, Zhang Shurong wrote:
> > 在 2023年8月29日星期二 CST 上午1:28:22,Laurent Pinchart 写道:
> > > Hi Zhang,
> > >
> > > Thank you for the patch.
> > >
> > > On Tue, Aug 29, 2023 at 12:55:01AM +0800, Zhang Shurong wrote:
> > > > of_match_device() may fail and returns a NULL pointer.
> > >
> > > How can it return a NULL pointer here ?
> > >
> > > > Fix this by checking the return value of of_match_device().
> > > >
> > > > Fixes: 3818715f62b4 ("drm/bridge: imx: Add LDB support for i.MX8qxp")
> > > > Signed-off-by: Zhang Shurong <zhang_shurong@foxmail.com>
> > > > ---
> > > >
> > > >  drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c | 2 ++
> > > >  1 file changed, 2 insertions(+)
> > > >
> > > > diff --git a/drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c
> > > > b/drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c index
> > > > 7984da9c0a35..d272f35c8eac 100644
> > > > --- a/drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c
> > > > +++ b/drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c
> > > > @@ -488,6 +488,8 @@ static int
> imx8qxp_ldb_parse_dt_companion(struct imx8qxp_ldb *imx8qxp_ldb)
> > > >  	 * string.
> > > >  	 */
> > > >  	match = of_match_device(dev->driver->of_match_table, dev);
> > > > +	if (!match)
> > > > +		return -ENODEV;
> > > >  	if (!of_device_is_compatible(companion, match->compatible)) {
> > > >  		DRM_DEV_ERROR(dev, "companion LDB is incompatible\n");
> > > >  		ret = -ENXIO;
> >
> > I think we can make it happen by designing the platform device in a way
> that
> > its name aligns with that of the driver. In such a scenario, when the driver
> > is probed, the of_match_device function will return null. You can verify this
> > functionality by reviewing the following function:
> >
> > static int platform_match(struct device *dev, struct device_driver *drv)
> 
> This particular device is found in OF-based systems only, and only
> instantiated through DT. You can create a platform_device manually that
> may match this driver, but that would be a made-up situation, not
> something that can happen in practice.
> 

I agree with Laurent.

Regards,
Liu Ying
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-08-29  2:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-28 16:55 [PATCH] drm/bridge: imx: fix potential NULL pointer dereference in imx8qxp_ldb_parse_dt_companion() Zhang Shurong
2023-08-28 17:28 ` Laurent Pinchart
2023-08-28 18:01   ` Zhang Shurong
2023-08-28 18:37     ` Laurent Pinchart
2023-08-29  2:28       ` Ying Liu

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).