From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anatolij Gustschin Date: Sat, 10 Nov 2012 01:01:37 +0100 Subject: [U-Boot] [PATCH v6 04/26] pmic: Extend PMIC framework to support multiple instances of PMIC devices In-Reply-To: <1352446951-12558-5-git-send-email-l.majewski@samsung.com> References: <1352446951-12558-1-git-send-email-l.majewski@samsung.com> <1352446951-12558-5-git-send-email-l.majewski@samsung.com> Message-ID: <20121110010137.43bdaab4@wker> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hi Lukasz, On Fri, 09 Nov 2012 08:42:09 +0100 Lukasz Majewski 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 > #include > #include > -#include > +#include > #include > #include > #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 > #include > -#include > +#include > #include > > #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