All of lore.kernel.org
 help / color / mirror / Atom feed
From: Corentin Labbe <clabbe.montjoie@gmail.com>
To: Shailendra Verma <shailendra.v@samsung.com>
Cc: Mark Yao <mark.yao@rock-chips.com>,
	David Airlie <airlied@linux.ie>, Heiko Stuebner <heiko@sntech.de>,
	dri-devel@lists.freedesktop.org,
	linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org,
	p.shailesh@samsung.com, ashish.kalra@samsung.com,
	Shailendra Verma <shailendra.capricorn@gmail.com>
Subject: Re: [PATCH] Gpu: drm: rockchip - Fix possible NULL derefrence.
Date: Fri, 27 Jan 2017 13:43:19 +0100	[thread overview]
Message-ID: <20170127124319.GA13611@Red> (raw)
In-Reply-To: <1485515510-3129-1-git-send-email-shailendra.v@samsung.com>

On Fri, Jan 27, 2017 at 04:41:50PM +0530, Shailendra Verma wrote:
> of_match_device could return NULL, and so can cause a NULL
> pointer dereference later.
> 
> Signed-off-by: Shailendra Verma <shailendra.v@samsung.com>
> ---
>  drivers/gpu/drm/rockchip/dw-mipi-dsi.c |   13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/rockchip/dw-mipi-dsi.c b/drivers/gpu/drm/rockchip/dw-mipi-dsi.c
> index ca22e5e..dbb99cf 100644
> --- a/drivers/gpu/drm/rockchip/dw-mipi-dsi.c
> +++ b/drivers/gpu/drm/rockchip/dw-mipi-dsi.c
> @@ -1082,15 +1082,22 @@ static enum drm_mode_status rk3288_mipi_dsi_mode_valid(
>  static int dw_mipi_dsi_bind(struct device *dev, struct device *master,
>  			     void *data)
>  {
> -	const struct of_device_id *of_id =
> -			of_match_device(dw_mipi_dsi_dt_ids, dev);
> -	const struct dw_mipi_dsi_plat_data *pdata = of_id->data;
> +	const struct of_device_id *of_id;
> +	const struct dw_mipi_dsi_plat_data *pdata;
>  	struct platform_device *pdev = to_platform_device(dev);
>  	struct drm_device *drm = data;
>  	struct dw_mipi_dsi *dsi;
>  	struct resource *res;
>  	int ret;
>  
> +	of_id = of_match_device(dw_mipi_dsi_dt_ids, dev);
> +	if (!of_id) {
> +		dev_err(dev, "Error: No device match found\n");
> +		return -ENODEV;
> +	}
> +
> +	pdata = of_id->data;
> +
>  	dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL);
>  	if (!dsi)
>  		return -ENOMEM;

Hello

You could use of_device_get_match_data()

Regards
Corentin Labbe

WARNING: multiple messages have this Message-ID (diff)
From: Corentin Labbe <clabbe.montjoie@gmail.com>
To: Shailendra Verma <shailendra.v@samsung.com>
Cc: ashish.kalra@samsung.com, linux-kernel@vger.kernel.org,
	dri-devel@lists.freedesktop.org,
	linux-rockchip@lists.infradead.org, p.shailesh@samsung.com,
	Shailendra Verma <shailendra.capricorn@gmail.com>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] Gpu: drm: rockchip - Fix possible NULL derefrence.
Date: Fri, 27 Jan 2017 13:43:19 +0100	[thread overview]
Message-ID: <20170127124319.GA13611@Red> (raw)
In-Reply-To: <1485515510-3129-1-git-send-email-shailendra.v@samsung.com>

On Fri, Jan 27, 2017 at 04:41:50PM +0530, Shailendra Verma wrote:
> of_match_device could return NULL, and so can cause a NULL
> pointer dereference later.
> 
> Signed-off-by: Shailendra Verma <shailendra.v@samsung.com>
> ---
>  drivers/gpu/drm/rockchip/dw-mipi-dsi.c |   13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/rockchip/dw-mipi-dsi.c b/drivers/gpu/drm/rockchip/dw-mipi-dsi.c
> index ca22e5e..dbb99cf 100644
> --- a/drivers/gpu/drm/rockchip/dw-mipi-dsi.c
> +++ b/drivers/gpu/drm/rockchip/dw-mipi-dsi.c
> @@ -1082,15 +1082,22 @@ static enum drm_mode_status rk3288_mipi_dsi_mode_valid(
>  static int dw_mipi_dsi_bind(struct device *dev, struct device *master,
>  			     void *data)
>  {
> -	const struct of_device_id *of_id =
> -			of_match_device(dw_mipi_dsi_dt_ids, dev);
> -	const struct dw_mipi_dsi_plat_data *pdata = of_id->data;
> +	const struct of_device_id *of_id;
> +	const struct dw_mipi_dsi_plat_data *pdata;
>  	struct platform_device *pdev = to_platform_device(dev);
>  	struct drm_device *drm = data;
>  	struct dw_mipi_dsi *dsi;
>  	struct resource *res;
>  	int ret;
>  
> +	of_id = of_match_device(dw_mipi_dsi_dt_ids, dev);
> +	if (!of_id) {
> +		dev_err(dev, "Error: No device match found\n");
> +		return -ENODEV;
> +	}
> +
> +	pdata = of_id->data;
> +
>  	dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL);
>  	if (!dsi)
>  		return -ENOMEM;

Hello

You could use of_device_get_match_data()

Regards
Corentin Labbe
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

WARNING: multiple messages have this Message-ID (diff)
From: clabbe.montjoie@gmail.com (Corentin Labbe)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] Gpu: drm: rockchip - Fix possible NULL derefrence.
Date: Fri, 27 Jan 2017 13:43:19 +0100	[thread overview]
Message-ID: <20170127124319.GA13611@Red> (raw)
In-Reply-To: <1485515510-3129-1-git-send-email-shailendra.v@samsung.com>

On Fri, Jan 27, 2017 at 04:41:50PM +0530, Shailendra Verma wrote:
> of_match_device could return NULL, and so can cause a NULL
> pointer dereference later.
> 
> Signed-off-by: Shailendra Verma <shailendra.v@samsung.com>
> ---
>  drivers/gpu/drm/rockchip/dw-mipi-dsi.c |   13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/rockchip/dw-mipi-dsi.c b/drivers/gpu/drm/rockchip/dw-mipi-dsi.c
> index ca22e5e..dbb99cf 100644
> --- a/drivers/gpu/drm/rockchip/dw-mipi-dsi.c
> +++ b/drivers/gpu/drm/rockchip/dw-mipi-dsi.c
> @@ -1082,15 +1082,22 @@ static enum drm_mode_status rk3288_mipi_dsi_mode_valid(
>  static int dw_mipi_dsi_bind(struct device *dev, struct device *master,
>  			     void *data)
>  {
> -	const struct of_device_id *of_id =
> -			of_match_device(dw_mipi_dsi_dt_ids, dev);
> -	const struct dw_mipi_dsi_plat_data *pdata = of_id->data;
> +	const struct of_device_id *of_id;
> +	const struct dw_mipi_dsi_plat_data *pdata;
>  	struct platform_device *pdev = to_platform_device(dev);
>  	struct drm_device *drm = data;
>  	struct dw_mipi_dsi *dsi;
>  	struct resource *res;
>  	int ret;
>  
> +	of_id = of_match_device(dw_mipi_dsi_dt_ids, dev);
> +	if (!of_id) {
> +		dev_err(dev, "Error: No device match found\n");
> +		return -ENODEV;
> +	}
> +
> +	pdata = of_id->data;
> +
>  	dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL);
>  	if (!dsi)
>  		return -ENOMEM;

Hello

You could use of_device_get_match_data()

Regards
Corentin Labbe

  reply	other threads:[~2017-01-27 12:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20170127111200epcas3p34bf747c6c3c0da798ddaf34788d1a324@epcas3p3.samsung.com>
2017-01-27 11:11 ` [PATCH] Gpu: drm: rockchip - Fix possible NULL derefrence Shailendra Verma
2017-01-27 11:11   ` Shailendra Verma
2017-01-27 11:11   ` Shailendra Verma
2017-01-27 12:43   ` Corentin Labbe [this message]
2017-01-27 12:43     ` Corentin Labbe
2017-01-27 12:43     ` Corentin Labbe

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=20170127124319.GA13611@Red \
    --to=clabbe.montjoie@gmail.com \
    --cc=airlied@linux.ie \
    --cc=ashish.kalra@samsung.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=heiko@sntech.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=mark.yao@rock-chips.com \
    --cc=p.shailesh@samsung.com \
    --cc=shailendra.capricorn@gmail.com \
    --cc=shailendra.v@samsung.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.