All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ben Dooks <ben-i2c-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org>
To: Michael Williamson
	<michael.williamson-wZX4cNJlHJ2sVWG7oymsAA@public.gmane.org>
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org,
	davinci-linux-open-source-VycZQUHpC/PFrsHnngEfi1aTQe2KTcn/@public.gmane.org,
	nsekhar-l0cyMroinI0@public.gmane.org,
	chaithrika-l0cyMroinI0@public.gmane.org
Subject: Re: [PATCH] i2c: davinci: Fix null dereference bug in i2c_davinci_calc_clk_dividers
Date: Mon, 2 May 2011 10:36:01 +0100	[thread overview]
Message-ID: <20110502093601.GW15795@trinity.fluff.org> (raw)
In-Reply-To: <1303579895-9441-1-git-send-email-michael.williamson-wZX4cNJlHJ2sVWG7oymsAA@public.gmane.org>

On Sat, Apr 23, 2011 at 01:31:35PM -0400, Michael Williamson wrote:
> The davinci-i2c bus driver currently supports being probed with a NULL
> platform_data structure by using a default configuration when none is
> provided.  However, the i2c_davinci_calc_clk_dividers does not
> check the provided platform_data for NULL prior to using it, so
> the support is incomplete.
> 
> Rather than have each runtime call check for NULL and avoid future
> problems, copy a pointer to the default data to the device structure
> during the probe.  This should be OK, as the information in this
> structure is not modified by the driver.
> 
> Tested on a MityDSP-L138 module (OMAP-L138 based SOM).
> 
> Signed-off-by: Micahel Williamson <michael.williamson-wZX4cNJlHJ2sVWG7oymsAA@public.gmane.org>
> ---
>  drivers/i2c/busses/i2c-davinci.c |   12 +++++-------
>  1 files changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
> index 5795c83..1db8fc9 100644
> --- a/drivers/i2c/busses/i2c-davinci.c
> +++ b/drivers/i2c/busses/i2c-davinci.c
> @@ -163,8 +163,7 @@ static void i2c_recover_bus(struct davinci_i2c_dev *dev)
>  	flag |=  DAVINCI_I2C_MDR_NACK;
>  	/* write the data into mode register */
>  	davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag);
> -	if (pdata)
> -		generic_i2c_clock_pulse(pdata->scl_pin);
> +	generic_i2c_clock_pulse(pdata->scl_pin);

This looks like a change in the behaviour of the code, since if there was
no pdata supplied we now can try generic_i2c_clock_pulse() with what is
probably gpio pin 0.

>  	/* Send STOP */
>  	flag = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG);
>  	flag |= DAVINCI_I2C_MDR_STP;
> @@ -235,10 +234,11 @@ static void i2c_davinci_calc_clk_dividers(struct davinci_i2c_dev *dev)
>   */
>  static int i2c_davinci_init(struct davinci_i2c_dev *dev)
>  {
> -	struct davinci_i2c_platform_data *pdata = dev->dev->platform_data;
> +	struct davinci_i2c_platform_data *pdata;
>  
> -	if (!pdata)
> -		pdata = &davinci_i2c_platform_data_default;
> +	if (!dev->dev->platform_data)
> +		dev->dev->platform_data = &davinci_i2c_platform_data_default;
> +	pdata = dev->dev->platform_data;

Hmm, not going to work well if the driver is a module, as you'll unload
the module, leave the default pointer in and then re-load later at a
possibly different address with the old pointer in.
  
>  	/* put I2C into reset */
>  	davinci_i2c_reset_ctrl(dev, 0);
> @@ -313,8 +313,6 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
>  	u16 w;
>  	int r;
>  
> -	if (!pdata)
> -		pdata = &davinci_i2c_platform_data_default;
>  	/* Introduce a delay, required for some boards (e.g Davinci EVM) */
>  	if (pdata->bus_delay)
>  		udelay(pdata->bus_delay);
> -- 
> 1.7.0.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
Ben Dooks, ben-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org, http://www.fluff.org/ben/

Large Hadron Colada: A large Pina Colada that makes the universe disappear.

  parent reply	other threads:[~2011-05-02  9:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-23 17:31 [PATCH] i2c: davinci: Fix null dereference bug in i2c_davinci_calc_clk_dividers Michael Williamson
     [not found] ` <1303579895-9441-1-git-send-email-michael.williamson-wZX4cNJlHJ2sVWG7oymsAA@public.gmane.org>
2011-05-02  9:36   ` Ben Dooks [this message]
     [not found]     ` <20110502093601.GW15795-SMNkleLxa3Z6Wcw2j4pizdi2O/JbrIOy@public.gmane.org>
2011-05-02 11:38       ` Michael Williamson

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=20110502093601.GW15795@trinity.fluff.org \
    --to=ben-i2c-elnmno+kys3ytjvyw6ydsg@public.gmane.org \
    --cc=ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org \
    --cc=chaithrika-l0cyMroinI0@public.gmane.org \
    --cc=davinci-linux-open-source-VycZQUHpC/PFrsHnngEfi1aTQe2KTcn/@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=michael.williamson-wZX4cNJlHJ2sVWG7oymsAA@public.gmane.org \
    --cc=nsekhar-l0cyMroinI0@public.gmane.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 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.