mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] mc13xxx: Added mc13xxx_revision() function.
@ 2012-08-04  9:15 Alexander Shiyan
  2012-08-04  9:15 ` [PATCH 2/3] mc13xxx: Hide private struct mc13xxx from other units Alexander Shiyan
  2012-08-04  9:15 ` [PATCH 3/3] mc13xxx: Fixed memory leak Alexander Shiyan
  0 siblings, 2 replies; 6+ messages in thread
From: Alexander Shiyan @ 2012-08-04  9:15 UTC (permalink / raw)
  To: barebox


Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 arch/arm/boards/ccxmx51/ccxmx51.c          |    2 +-
 arch/arm/boards/freescale-mx51-pdk/board.c |    2 +-
 drivers/mfd/mc13xxx.c                      |    6 ++++++
 include/mfd/mc13xxx.h                      |    6 ++++++
 4 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boards/ccxmx51/ccxmx51.c b/arch/arm/boards/ccxmx51/ccxmx51.c
index f309e0c..0b450d6 100644
--- a/arch/arm/boards/ccxmx51/ccxmx51.c
+++ b/arch/arm/boards/ccxmx51/ccxmx51.c
@@ -307,7 +307,7 @@ static int ccxmx51_power_init(void)
 		mc13xxx_reg_write(mc13xxx_dev, MC13892_REG_SW_2, val);
 	}
 
-	if (mc13xxx_dev->revision <= MC13892_REVISION_2_0) {
+	if (mc13xxx_revision(mc13xxx_dev) <= MC13892_REVISION_2_0) {
 		/* Set switchers in PWM mode for Atlas 2.0 and lower */
 		/* Setup the switcher mode for SW1 & SW2*/
 		mc13xxx_reg_read(mc13xxx_dev, MC13892_REG_SW_4, &val);
diff --git a/arch/arm/boards/freescale-mx51-pdk/board.c b/arch/arm/boards/freescale-mx51-pdk/board.c
index 7c2c8fe..b67a509 100644
--- a/arch/arm/boards/freescale-mx51-pdk/board.c
+++ b/arch/arm/boards/freescale-mx51-pdk/board.c
@@ -178,7 +178,7 @@ static void babbage_power_init(void)
 		mc13xxx_reg_write(mc13xxx, MC13892_REG_SW_2, val);
 	}
 
-	if (mc13xxx->revision < MC13892_REVISION_2_0) {
+	if (mc13xxx_revision(mc13xxx) < MC13892_REVISION_2_0) {
 		/* Set switchers in PWM mode for Atlas 2.0 and lower */
 		/* Setup the switcher mode for SW1 & SW2*/
 		mc13xxx_reg_read(mc13xxx, MC13892_REG_SW_4, &val);
diff --git a/drivers/mfd/mc13xxx.c b/drivers/mfd/mc13xxx.c
index 8bb0d00..53d9b7c 100644
--- a/drivers/mfd/mc13xxx.c
+++ b/drivers/mfd/mc13xxx.c
@@ -42,6 +42,12 @@ struct mc13xxx *mc13xxx_get(void)
 }
 EXPORT_SYMBOL(mc13xxx_get);
 
+int mc13xxx_revision(struct mc13xxx *mc13xxx)
+{
+	return mc13xxx->revision;
+}
+EXPORT_SYMBOL(mc13xxx_revision);
+
 #ifdef CONFIG_SPI
 static int spi_rw(struct spi_device *spi, void * buf, size_t len)
 {
diff --git a/include/mfd/mc13xxx.h b/include/mfd/mc13xxx.h
index 632c9fb..3770789 100644
--- a/include/mfd/mc13xxx.h
+++ b/include/mfd/mc13xxx.h
@@ -165,6 +165,7 @@ struct mc13xxx {
 
 #ifdef CONFIG_MFD_MC13XXX
 extern struct mc13xxx *mc13xxx_get(void);
+extern int mc13xxx_revision(struct mc13xxx *mc13xxx);
 extern int mc13xxx_reg_read(struct mc13xxx *mc13xxx, u8 reg, u32 *val);
 extern int mc13xxx_reg_write(struct mc13xxx *mc13xxx, u8 reg, u32 val);
 extern int mc13xxx_set_bits(struct mc13xxx *mc13xxx, u8 reg, u32 mask, u32 val);
@@ -174,6 +175,11 @@ static inline struct mc13xxx *mc13xxx_get(void)
 	return NULL;
 }
 
+static inline int mc13xxx_revision(struct mc13xxx *mc13xxx)
+{
+	return -ENODEV;
+}
+
 static inline int mc13xxx_reg_read(struct mc13xxx *mc13xxx, u8 reg, u32 *val)
 {
 	return -ENODEV;
-- 
1.7.3.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/3] mc13xxx: Hide private struct mc13xxx from other units
  2012-08-04  9:15 [PATCH 1/3] mc13xxx: Added mc13xxx_revision() function Alexander Shiyan
@ 2012-08-04  9:15 ` Alexander Shiyan
  2012-08-04  9:15 ` [PATCH 3/3] mc13xxx: Fixed memory leak Alexander Shiyan
  1 sibling, 0 replies; 6+ messages in thread
From: Alexander Shiyan @ 2012-08-04  9:15 UTC (permalink / raw)
  To: barebox

Board support units must use only the provided functions.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 drivers/mfd/mc13xxx.c |   15 +++++++++++++++
 include/mfd/mc13xxx.h |   13 +------------
 2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/drivers/mfd/mc13xxx.c b/drivers/mfd/mc13xxx.c
index 53d9b7c..8e3c0b0 100644
--- a/drivers/mfd/mc13xxx.c
+++ b/drivers/mfd/mc13xxx.c
@@ -32,6 +32,21 @@
 
 #define DRIVERNAME		"mc13xxx"
 
+enum mc13xxx_mode {
+	MC13XXX_MODE_I2C,
+	MC13XXX_MODE_SPI,
+};
+
+struct mc13xxx {
+	struct cdev			cdev;
+	union {
+		struct i2c_client	*client;
+		struct spi_device	*spi;
+	};
+	enum mc13xxx_mode		mode;
+	int				revision;
+};
+
 #define to_mc13xxx(a)		container_of(a, struct mc13xxx, cdev)
 
 static struct mc13xxx *mc_dev;
diff --git a/include/mfd/mc13xxx.h b/include/mfd/mc13xxx.h
index 3770789..59042eb 100644
--- a/include/mfd/mc13xxx.h
+++ b/include/mfd/mc13xxx.h
@@ -150,18 +150,7 @@
 #define MC13783_SW1B_SOFTSTART		(1 << 17)
 #define MC13783_SW_PLL_FACTOR(x)	(((x) - 28) << 19)
 
-enum mc13xxx_mode {
-	MC13XXX_MODE_I2C,
-	MC13XXX_MODE_SPI,
-};
-
-struct mc13xxx {
-	struct cdev		cdev;
-	struct i2c_client	*client;
-	struct spi_device	*spi;
-	enum mc13xxx_mode	mode;
-	int			revision;
-};
+struct mc13xxx;
 
 #ifdef CONFIG_MFD_MC13XXX
 extern struct mc13xxx *mc13xxx_get(void);
-- 
1.7.3.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/3] mc13xxx: Fixed memory leak
  2012-08-04  9:15 [PATCH 1/3] mc13xxx: Added mc13xxx_revision() function Alexander Shiyan
  2012-08-04  9:15 ` [PATCH 2/3] mc13xxx: Hide private struct mc13xxx from other units Alexander Shiyan
@ 2012-08-04  9:15 ` Alexander Shiyan
  2012-08-09  6:38   ` Sascha Hauer
  1 sibling, 1 reply; 6+ messages in thread
From: Alexander Shiyan @ 2012-08-04  9:15 UTC (permalink / raw)
  To: barebox

A string allocated by asprintf is not freed, so change it to a sprintf
with the preallocated buffer.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 drivers/mfd/mc13xxx.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/mfd/mc13xxx.c b/drivers/mfd/mc13xxx.c
index 8e3c0b0..2373254 100644
--- a/drivers/mfd/mc13xxx.c
+++ b/drivers/mfd/mc13xxx.c
@@ -252,7 +252,7 @@ static struct mc13892_rev mc13892_revisions[] = {
 static int mc13xxx_query_revision(struct mc13xxx *mc13xxx)
 {
 	unsigned int rev_id;
-	char *chipname, *revstr;
+	char *chipname, revstr[5];
 	int rev, i;
 
 	mc13xxx_reg_read(mc13xxx, MC13XXX_REG_IDENTIFICATION, &rev_id);
@@ -265,9 +265,9 @@ static int mc13xxx_query_revision(struct mc13xxx *mc13xxx)
 		/* Ver 0.2 is actually 3.2a. Report as 3.2 */
 		if (rev == 0x02) {
 			rev = 0x32;
-			revstr = "3.2a";
+			strcpy(&revstr[0], "3.2a");
 		} else
-			revstr = asprintf("%d.%d", rev / 0x10, rev % 10);
+			sprintf(&revstr[0], "%d.%d", rev / 0x10, rev % 10);
 		break;
 	case 7:
 		chipname = "MC13892";
@@ -279,12 +279,12 @@ static int mc13xxx_query_revision(struct mc13xxx *mc13xxx)
 			return -EINVAL;
 
 		rev = mc13892_revisions[i].rev;
-		revstr = mc13892_revisions[i].revstr;
+		strcpy(&revstr[0], mc13892_revisions[i].revstr);
 
 		if (rev == MC13892_REVISION_2_0) {
 			if ((rev_id >> 9) & 0x3) {
 				rev = MC13892_REVISION_2_0a;
-				revstr = "2.0a";
+				strcpy(&revstr[0], "2.0a");
 			}
 		}
 		break;
@@ -294,7 +294,7 @@ static int mc13xxx_query_revision(struct mc13xxx *mc13xxx)
 	}
 
 	dev_info(mc_dev->cdev.dev, "Found %s ID: 0x%06x [Rev: %s]\n",
-			chipname, rev_id, revstr);
+			chipname, rev_id, &revstr[0]);
 
 	mc13xxx->revision = rev;
 
-- 
1.7.3.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 3/3] mc13xxx: Fixed memory leak
  2012-08-04  9:15 ` [PATCH 3/3] mc13xxx: Fixed memory leak Alexander Shiyan
@ 2012-08-09  6:38   ` Sascha Hauer
  2012-08-09 15:33     ` Alexander Shiyan
  0 siblings, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2012-08-09  6:38 UTC (permalink / raw)
  To: Alexander Shiyan; +Cc: barebox

On Sat, Aug 04, 2012 at 01:15:55PM +0400, Alexander Shiyan wrote:
> A string allocated by asprintf is not freed, so change it to a sprintf
> with the preallocated buffer.
> 
> Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
> ---
>  drivers/mfd/mc13xxx.c |   12 ++++++------
>  1 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/mfd/mc13xxx.c b/drivers/mfd/mc13xxx.c
> index 8e3c0b0..2373254 100644
> --- a/drivers/mfd/mc13xxx.c
> +++ b/drivers/mfd/mc13xxx.c
> @@ -252,7 +252,7 @@ static struct mc13892_rev mc13892_revisions[] = {
>  static int mc13xxx_query_revision(struct mc13xxx *mc13xxx)
>  {
>  	unsigned int rev_id;
> -	char *chipname, *revstr;
> +	char *chipname, revstr[5];
>  	int rev, i;
>  
>  	mc13xxx_reg_read(mc13xxx, MC13XXX_REG_IDENTIFICATION, &rev_id);
> @@ -265,9 +265,9 @@ static int mc13xxx_query_revision(struct mc13xxx *mc13xxx)
>  		/* Ver 0.2 is actually 3.2a. Report as 3.2 */
>  		if (rev == 0x02) {
>  			rev = 0x32;
> -			revstr = "3.2a";
> +			strcpy(&revstr[0], "3.2a");
>  		} else
> -			revstr = asprintf("%d.%d", rev / 0x10, rev % 10);
> +			sprintf(&revstr[0], "%d.%d", rev / 0x10, rev % 10);
>  		break;
>  	case 7:
>  		chipname = "MC13892";
> @@ -279,12 +279,12 @@ static int mc13xxx_query_revision(struct mc13xxx *mc13xxx)
>  			return -EINVAL;
>  
>  		rev = mc13892_revisions[i].rev;
> -		revstr = mc13892_revisions[i].revstr;
> +		strcpy(&revstr[0], mc13892_revisions[i].revstr);
>  
>  		if (rev == MC13892_REVISION_2_0) {
>  			if ((rev_id >> 9) & 0x3) {
>  				rev = MC13892_REVISION_2_0a;
> -				revstr = "2.0a";
> +				strcpy(&revstr[0], "2.0a");

strcpy(revstr, "2.0a") should do the same, right? (also for the other
places)

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/3] mc13xxx: Fixed memory leak
  2012-08-09  6:38   ` Sascha Hauer
@ 2012-08-09 15:33     ` Alexander Shiyan
  2012-08-10  8:44       ` Sascha Hauer
  0 siblings, 1 reply; 6+ messages in thread
From: Alexander Shiyan @ 2012-08-09 15:33 UTC (permalink / raw)
  To: barebox

A string allocated by asprintf is not freed, so change it to a sprintf
with the preallocated buffer.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 drivers/mfd/mc13xxx.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/mfd/mc13xxx.c b/drivers/mfd/mc13xxx.c
index 8e3c0b0..704446d 100644
--- a/drivers/mfd/mc13xxx.c
+++ b/drivers/mfd/mc13xxx.c
@@ -252,7 +252,7 @@ static struct mc13892_rev mc13892_revisions[] = {
 static int mc13xxx_query_revision(struct mc13xxx *mc13xxx)
 {
 	unsigned int rev_id;
-	char *chipname, *revstr;
+	char *chipname, revstr[5];
 	int rev, i;
 
 	mc13xxx_reg_read(mc13xxx, MC13XXX_REG_IDENTIFICATION, &rev_id);
@@ -265,9 +265,9 @@ static int mc13xxx_query_revision(struct mc13xxx *mc13xxx)
 		/* Ver 0.2 is actually 3.2a. Report as 3.2 */
 		if (rev == 0x02) {
 			rev = 0x32;
-			revstr = "3.2a";
+			strcpy(revstr, "3.2a");
 		} else
-			revstr = asprintf("%d.%d", rev / 0x10, rev % 10);
+			sprintf(revstr, "%d.%d", rev / 0x10, rev % 10);
 		break;
 	case 7:
 		chipname = "MC13892";
@@ -279,12 +279,12 @@ static int mc13xxx_query_revision(struct mc13xxx *mc13xxx)
 			return -EINVAL;
 
 		rev = mc13892_revisions[i].rev;
-		revstr = mc13892_revisions[i].revstr;
+		strcpy(revstr, mc13892_revisions[i].revstr);
 
 		if (rev == MC13892_REVISION_2_0) {
 			if ((rev_id >> 9) & 0x3) {
 				rev = MC13892_REVISION_2_0a;
-				revstr = "2.0a";
+				strcpy(revstr, "2.0a");
 			}
 		}
 		break;
-- 
1.7.3.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 3/3] mc13xxx: Fixed memory leak
  2012-08-09 15:33     ` Alexander Shiyan
@ 2012-08-10  8:44       ` Sascha Hauer
  0 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2012-08-10  8:44 UTC (permalink / raw)
  To: Alexander Shiyan; +Cc: barebox

On Thu, Aug 09, 2012 at 07:33:08PM +0400, Alexander Shiyan wrote:
> A string allocated by asprintf is not freed, so change it to a sprintf
> with the preallocated buffer.
> 
> Signed-off-by: Alexander Shiyan <shc_work@mail.ru>

Applied, thanks.

Sascha

> ---
>  drivers/mfd/mc13xxx.c |   10 +++++-----
>  1 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/mfd/mc13xxx.c b/drivers/mfd/mc13xxx.c
> index 8e3c0b0..704446d 100644
> --- a/drivers/mfd/mc13xxx.c
> +++ b/drivers/mfd/mc13xxx.c
> @@ -252,7 +252,7 @@ static struct mc13892_rev mc13892_revisions[] = {
>  static int mc13xxx_query_revision(struct mc13xxx *mc13xxx)
>  {
>  	unsigned int rev_id;
> -	char *chipname, *revstr;
> +	char *chipname, revstr[5];
>  	int rev, i;
>  
>  	mc13xxx_reg_read(mc13xxx, MC13XXX_REG_IDENTIFICATION, &rev_id);
> @@ -265,9 +265,9 @@ static int mc13xxx_query_revision(struct mc13xxx *mc13xxx)
>  		/* Ver 0.2 is actually 3.2a. Report as 3.2 */
>  		if (rev == 0x02) {
>  			rev = 0x32;
> -			revstr = "3.2a";
> +			strcpy(revstr, "3.2a");
>  		} else
> -			revstr = asprintf("%d.%d", rev / 0x10, rev % 10);
> +			sprintf(revstr, "%d.%d", rev / 0x10, rev % 10);
>  		break;
>  	case 7:
>  		chipname = "MC13892";
> @@ -279,12 +279,12 @@ static int mc13xxx_query_revision(struct mc13xxx *mc13xxx)
>  			return -EINVAL;
>  
>  		rev = mc13892_revisions[i].rev;
> -		revstr = mc13892_revisions[i].revstr;
> +		strcpy(revstr, mc13892_revisions[i].revstr);
>  
>  		if (rev == MC13892_REVISION_2_0) {
>  			if ((rev_id >> 9) & 0x3) {
>  				rev = MC13892_REVISION_2_0a;
> -				revstr = "2.0a";
> +				strcpy(revstr, "2.0a");
>  			}
>  		}
>  		break;
> -- 
> 1.7.3.4
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-08-10  8:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-04  9:15 [PATCH 1/3] mc13xxx: Added mc13xxx_revision() function Alexander Shiyan
2012-08-04  9:15 ` [PATCH 2/3] mc13xxx: Hide private struct mc13xxx from other units Alexander Shiyan
2012-08-04  9:15 ` [PATCH 3/3] mc13xxx: Fixed memory leak Alexander Shiyan
2012-08-09  6:38   ` Sascha Hauer
2012-08-09 15:33     ` Alexander Shiyan
2012-08-10  8:44       ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox