[U-Boot] [PATCH v6 04/26] pmic: Extend PMIC framework to support multiple instances of PMIC devices

Anatolij Gustschin agust at denx.de
Sat Nov 10 01:01:37 CET 2012


Hi Lukasz,

On Fri, 09 Nov 2012 08:42:09 +0100
Lukasz Majewski <l.majewski at samsung.com> wrote:
...
> diff --git a/board/davedenx/qong/qong.c b/board/davedenx/qong/qong.c
> index c41f11d..e8c23f8 100644
> --- a/board/davedenx/qong/qong.c
> +++ b/board/davedenx/qong/qong.c
> @@ -28,7 +28,7 @@
>  #include <asm/arch/sys_proto.h>
>  #include <asm/io.h>
>  #include <nand.h>
> -#include <pmic.h>
> +#include <power/pmic.h>
>  #include <fsl_pmic.h>
>  #include <asm/gpio.h>
>  #include "qong_fpga.h"
> @@ -173,8 +173,8 @@ int board_late_init(void)
>  	u32 val;
>  	struct pmic *p;
>  
> -	pmic_init();
> -	p = get_pmic();
> +	pmic_init(I2C_PMIC);
> +	p = pmic_get("FSL_PMIC");

Now the pmic struct is allocated dynamically, we should check if the
allocation failed and bail out in this case to prevent dereferencing
null pointer in pmic_get().

...
> diff --git a/drivers/misc/pmic_fsl.c b/drivers/misc/pmic_fsl.c
> index 0ff75ed..868c3c4 100644
> --- a/drivers/misc/pmic_fsl.c
> +++ b/drivers/misc/pmic_fsl.c
> @@ -23,7 +23,7 @@
>  
>  #include <common.h>
>  #include <spi.h>
> -#include <pmic.h>
> +#include <power/pmic.h>
>  #include <fsl_pmic.h>
>  
>  #if defined(CONFIG_PMIC_SPI)
> @@ -33,9 +33,9 @@ static u32 pmic_spi_prepare_tx(u32 reg, u32 *val, u32 write)
>  }
>  #endif
>  
> -int pmic_init(void)
> +int pmic_init(unsigned char bus)
>  {
> -	struct pmic *p = get_pmic();
> +	struct pmic *p = pmic_alloc();
>  	static const char name[] = "FSL_PMIC";
>  
>  	p->name = name;
> @@ -54,7 +54,7 @@ int pmic_init(void)
>  	p->interface = PMIC_I2C;
>  	p->hw.i2c.addr = CONFIG_SYS_FSL_PMIC_I2C_ADDR;
>  	p->hw.i2c.tx_num = 3;
> -	p->bus = I2C_PMIC;
> +	p->bus = bus;

In the case the pmic_alloc() fails this code is now writing to pmic
struct at NULL. Please check the return value of pmic_alloc() and
bail out if needed. This applies to other drivers changed by this
patch. Can you please fix it and resubmit a fixed patch 04/26.

Thanks,
Anatolij


More information about the U-Boot mailing list