diff mbox

[2/2] backlight: lm3630: potential NULL deref in probe()

Message ID 20130925085549.GB6661@elgon.mountain (mailing list archive)
State New, archived
Headers show

Commit Message

Dan Carpenter Sept. 25, 2013, 8:55 a.m. UTC
We dereference "pdata" later in the function so we can't leave it as
NULL.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

--
To unsubscribe from this list: send the line "unsubscribe linux-fbdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Jingoo Han Sept. 25, 2013, 9:13 a.m. UTC | #1
On Wednesday, September 25, 2013 5:55 PM, Dan Carpenter wrote:
> 
> "rval" needs to be signed for the error handling to work.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

CC'ed Andrew Morton, Daniel Jeong,

Oh, you're right.
"rval" is used as below.
rval = lm3630a_read(pchip, REG_INT_STATUS);
Also, lm3630a_read() returns signed value; thus,
"rval" should be signed.
Thank you for sending the patch. :-)

Acked-by: Jingoo Han <jg1.han@samsung.com>

> 
> diff --git a/drivers/video/backlight/lm3630a_bl.c b/drivers/video/backlight/lm3630a_bl.c
> index c63f918..65392f9 100644
> --- a/drivers/video/backlight/lm3630a_bl.c
> +++ b/drivers/video/backlight/lm3630a_bl.c
> @@ -105,7 +105,7 @@ static int lm3630a_chip_init(struct lm3630a_chip *pchip)
>  /* interrupt handling */
>  static void lm3630a_delayed_func(struct work_struct *work)
>  {
> -	unsigned int rval;
> +	int rval;
>  	struct lm3630a_chip *pchip;
> 
>  	pchip = container_of(work, struct lm3630a_chip, work.work);


--
To unsubscribe from this list: send the line "unsubscribe linux-fbdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jingoo Han Sept. 25, 2013, 9:28 a.m. UTC | #2
On Wednesday, September 25, 2013 5:56 PM, Dan Carpenter wrote:
> 
> We dereference "pdata" later in the function so we can't leave it as
> NULL.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

CC'ed Andrew Morton, Daniel Jeong,

Acked-by: Jingoo Han <jg1.han@samsung.com>

> 
> diff --git a/drivers/video/backlight/lm3630a_bl.c b/drivers/video/backlight/lm3630a_bl.c
> index 65392f9..6146481 100644
> --- a/drivers/video/backlight/lm3630a_bl.c
> +++ b/drivers/video/backlight/lm3630a_bl.c
> @@ -389,22 +389,21 @@ static int lm3630a_probe(struct i2c_client *client,
> 
>  	i2c_set_clientdata(client, pchip);
>  	if (pdata == NULL) {
> -		pchip->pdata = devm_kzalloc(pchip->dev,
> -					    sizeof(struct
> -						   lm3630a_platform_data),
> -					    GFP_KERNEL);
> -		if (pchip->pdata == NULL)
> +		pdata = devm_kzalloc(pchip->dev,
> +				     sizeof(struct lm3630a_platform_data),
> +				     GFP_KERNEL);
> +		if (pdata == NULL)
>  			return -ENOMEM;
>  		/* default values */
> -		pchip->pdata->leda_ctrl = LM3630A_LEDA_ENABLE;
> -		pchip->pdata->ledb_ctrl = LM3630A_LEDB_ENABLE;
> -		pchip->pdata->leda_max_brt = LM3630A_MAX_BRIGHTNESS;
> -		pchip->pdata->ledb_max_brt = LM3630A_MAX_BRIGHTNESS;
> -		pchip->pdata->leda_init_brt = LM3630A_MAX_BRIGHTNESS;
> -		pchip->pdata->ledb_init_brt = LM3630A_MAX_BRIGHTNESS;
> -	} else {
> -		pchip->pdata = pdata;
> +		pdata->leda_ctrl = LM3630A_LEDA_ENABLE;
> +		pdata->ledb_ctrl = LM3630A_LEDB_ENABLE;
> +		pdata->leda_max_brt = LM3630A_MAX_BRIGHTNESS;
> +		pdata->ledb_max_brt = LM3630A_MAX_BRIGHTNESS;
> +		pdata->leda_init_brt = LM3630A_MAX_BRIGHTNESS;
> +		pdata->ledb_init_brt = LM3630A_MAX_BRIGHTNESS;
>  	}
> +	pchip->pdata = pdata;
> +
>  	/* chip initialize */
>  	rval = lm3630a_chip_init(pchip);
>  	if (rval < 0) {

--
To unsubscribe from this list: send the line "unsubscribe linux-fbdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Dan Carpenter Sept. 25, 2013, 9:34 a.m. UTC | #3
On Wed, Sep 25, 2013 at 06:13:28PM +0900, Jingoo Han wrote:
> On Wednesday, September 25, 2013 5:55 PM, Dan Carpenter wrote:
> > 
> > "rval" needs to be signed for the error handling to work.
> > 
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> CC'ed Andrew Morton, Daniel Jeong,
> 

Ah.  I didn't realize this driver was going through Andrew.  I will
resend the patches.

regards,
dan carpenter

--
To unsubscribe from this list: send the line "unsubscribe linux-fbdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/video/backlight/lm3630a_bl.c b/drivers/video/backlight/lm3630a_bl.c
index 65392f9..6146481 100644
--- a/drivers/video/backlight/lm3630a_bl.c
+++ b/drivers/video/backlight/lm3630a_bl.c
@@ -389,22 +389,21 @@  static int lm3630a_probe(struct i2c_client *client,
 
 	i2c_set_clientdata(client, pchip);
 	if (pdata == NULL) {
-		pchip->pdata = devm_kzalloc(pchip->dev,
-					    sizeof(struct
-						   lm3630a_platform_data),
-					    GFP_KERNEL);
-		if (pchip->pdata == NULL)
+		pdata = devm_kzalloc(pchip->dev,
+				     sizeof(struct lm3630a_platform_data),
+				     GFP_KERNEL);
+		if (pdata == NULL)
 			return -ENOMEM;
 		/* default values */
-		pchip->pdata->leda_ctrl = LM3630A_LEDA_ENABLE;
-		pchip->pdata->ledb_ctrl = LM3630A_LEDB_ENABLE;
-		pchip->pdata->leda_max_brt = LM3630A_MAX_BRIGHTNESS;
-		pchip->pdata->ledb_max_brt = LM3630A_MAX_BRIGHTNESS;
-		pchip->pdata->leda_init_brt = LM3630A_MAX_BRIGHTNESS;
-		pchip->pdata->ledb_init_brt = LM3630A_MAX_BRIGHTNESS;
-	} else {
-		pchip->pdata = pdata;
+		pdata->leda_ctrl = LM3630A_LEDA_ENABLE;
+		pdata->ledb_ctrl = LM3630A_LEDB_ENABLE;
+		pdata->leda_max_brt = LM3630A_MAX_BRIGHTNESS;
+		pdata->ledb_max_brt = LM3630A_MAX_BRIGHTNESS;
+		pdata->leda_init_brt = LM3630A_MAX_BRIGHTNESS;
+		pdata->ledb_init_brt = LM3630A_MAX_BRIGHTNESS;
 	}
+	pchip->pdata = pdata;
+
 	/* chip initialize */
 	rval = lm3630a_chip_init(pchip);
 	if (rval < 0) {