Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1324028 > unrolled thread

[PATCH] power: bq27xxx_battery: Restore device name

Started byIvaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
First post2016-02-02 13:20 +0100
Last post2016-02-02 13:50 +0100
Articles 9 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] power: bq27xxx_battery: Restore device name Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com> - 2016-02-02 13:20 +0100
    Re: [PATCH] power: bq27xxx_battery: Restore device name Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com> - 2016-02-02 13:30 +0100
    Re: [PATCH] power: bq27xxx_battery: Restore device name Pali Rohár <pali.rohar@gmail.com> - 2016-02-02 13:30 +0100
      Re: [PATCH] power: bq27xxx_battery: Restore device name Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com> - 2016-02-02 13:40 +0100
      Re: [PATCH v1] power: bq27xxx_battery: Restore device name Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com> - 2016-02-02 13:40 +0100
        [PATCH v2] power: bq27xxx_battery: Restore device name Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com> - 2016-02-02 13:50 +0100
          Re: [PATCH v2] power: bq27xxx_battery: Restore device name Pali Rohár <pali.rohar@gmail.com> - 2016-02-06 11:40 +0100
      [PATCH v1] power: bq27xxx_battery: Restore device name Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com> - 2016-02-02 13:40 +0100
        Re: [PATCH v1] power: bq27xxx_battery: Restore device name kbuild test robot <lkp@intel.com> - 2016-02-02 13:50 +0100

#1324028 — [PATCH] power: bq27xxx_battery: Restore device name

FromIvaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
Date2016-02-02 13:20 +0100
Subject[PATCH] power: bq27xxx_battery: Restore device name
Message-ID<qXI67-2I0-21@gated-at.bofh.it>
Patch <703df6c097956d17a818e63961c82e8e9eef9fef> ("power: bq27xxx_battery:
 Reorganize I2C into a module") has removed the device name numbering from
bq27xxx_battery_i2c_probe. Fix that by restoring the code.

Signed-off-by: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
---
 drivers/power/bq27xxx_battery_i2c.c | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/drivers/power/bq27xxx_battery_i2c.c b/drivers/power/bq27xxx_battery_i2c.c
index b810e08..d98cdc5 100644
--- a/drivers/power/bq27xxx_battery_i2c.c
+++ b/drivers/power/bq27xxx_battery_i2c.c
@@ -21,6 +21,9 @@
 
 #include <linux/power/bq27xxx_battery.h>
 
+static DEFINE_IDR(battery_id);
+static DEFINE_MUTEX(battery_mutex);
+
 static irqreturn_t bq27xxx_battery_irq_handler_thread(int irq, void *data)
 {
 	struct bq27xxx_device_info *di = data;
@@ -70,19 +73,32 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client,
 {
 	struct bq27xxx_device_info *di;
 	int ret;
+	char *name;
+	int num;
+
+	/* Get new ID for the new battery device */
+	mutex_lock(&battery_mutex);
+	num = idr_alloc(&battery_id, client, 0, 0, GFP_KERNEL);
+	mutex_unlock(&battery_mutex);
+	if (num < 0)
+		return num;
+
+	name = devm_kasprintf(&client->dev, GFP_KERNEL, "%s-%d", id->name, num);
+	if (!name)
+		goto err_mem;
 
 	di = devm_kzalloc(&client->dev, sizeof(*di), GFP_KERNEL);
 	if (!di)
-		return -ENOMEM;
+		goto err_mem;
 
 	di->dev = &client->dev;
 	di->chip = id->driver_data;
-	di->name = id->name;
+	di->name = name;
 	di->bus.read = bq27xxx_battery_i2c_read;
 
 	ret = bq27xxx_battery_setup(di);
 	if (ret)
-		return ret;
+		goto err_failed;
 
 	/* Schedule a polling after about 1 min */
 	schedule_delayed_work(&di->work, 60 * HZ);
@@ -103,6 +119,16 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client,
 	}
 
 	return 0;
+
+err_mem:
+	ret = -ENOMEM;
+
+err_failed:
+	mutex_lock(&battery_mutex);
+	idr_remove(&battery_id, num);
+	mutex_unlock(&battery_mutex);
+
+	return ret;
 }
 
 static int bq27xxx_battery_i2c_remove(struct i2c_client *client)
-- 
1.9.1

[toc] | [next] | [standalone]


#1324031

FromIvaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
Date2016-02-02 13:30 +0100
Message-ID<qXIfM-2Pu-1@gated-at.bofh.it>
In reply to#1324028
Sorry, I've sent an incomplete patch, ignore that, will re-send the full 
version

On  2.02.2016 14:15, Ivaylo Dimitrov wrote:
> Patch <703df6c097956d17a818e63961c82e8e9eef9fef> ("power: bq27xxx_battery:
>   Reorganize I2C into a module") has removed the device name numbering from
> bq27xxx_battery_i2c_probe. Fix that by restoring the code.
>
> Signed-off-by: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
> ---
>   drivers/power/bq27xxx_battery_i2c.c | 32 +++++++++++++++++++++++++++++---
>   1 file changed, 29 insertions(+), 3 deletions(-)

[toc] | [prev] | [next] | [standalone]


#1324035

FromPali Rohár <pali.rohar@gmail.com>
Date2016-02-02 13:30 +0100
Message-ID<qXIfM-2Pu-17@gated-at.bofh.it>
In reply to#1324028
On Tuesday 02 February 2016 14:15:19 Ivaylo Dimitrov wrote:
> Patch <703df6c097956d17a818e63961c82e8e9eef9fef> ("power: bq27xxx_battery:
>  Reorganize I2C into a module") has removed the device name numbering from
> bq27xxx_battery_i2c_probe. Fix that by restoring the code.
> 
> Signed-off-by: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
> ---
>  drivers/power/bq27xxx_battery_i2c.c | 32 +++++++++++++++++++++++++++++---
>  1 file changed, 29 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/power/bq27xxx_battery_i2c.c b/drivers/power/bq27xxx_battery_i2c.c
> index b810e08..d98cdc5 100644
> --- a/drivers/power/bq27xxx_battery_i2c.c
> +++ b/drivers/power/bq27xxx_battery_i2c.c
> @@ -21,6 +21,9 @@
>  
>  #include <linux/power/bq27xxx_battery.h>
>  
> +static DEFINE_IDR(battery_id);
> +static DEFINE_MUTEX(battery_mutex);
> +
>  static irqreturn_t bq27xxx_battery_irq_handler_thread(int irq, void *data)
>  {
>  	struct bq27xxx_device_info *di = data;
> @@ -70,19 +73,32 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client,
>  {
>  	struct bq27xxx_device_info *di;
>  	int ret;
> +	char *name;
> +	int num;
> +
> +	/* Get new ID for the new battery device */
> +	mutex_lock(&battery_mutex);
> +	num = idr_alloc(&battery_id, client, 0, 0, GFP_KERNEL);
> +	mutex_unlock(&battery_mutex);
> +	if (num < 0)
> +		return num;
> +
> +	name = devm_kasprintf(&client->dev, GFP_KERNEL, "%s-%d", id->name, num);
> +	if (!name)
> +		goto err_mem;
>  
>  	di = devm_kzalloc(&client->dev, sizeof(*di), GFP_KERNEL);
>  	if (!di)
> -		return -ENOMEM;
> +		goto err_mem;
>  
>  	di->dev = &client->dev;
>  	di->chip = id->driver_data;
> -	di->name = id->name;
> +	di->name = name;
>  	di->bus.read = bq27xxx_battery_i2c_read;
>  
>  	ret = bq27xxx_battery_setup(di);
>  	if (ret)
> -		return ret;
> +		goto err_failed;
>  
>  	/* Schedule a polling after about 1 min */
>  	schedule_delayed_work(&di->work, 60 * HZ);
> @@ -103,6 +119,16 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client,
>  	}
>  
>  	return 0;
> +
> +err_mem:
> +	ret = -ENOMEM;
> +
> +err_failed:
> +	mutex_lock(&battery_mutex);
> +	idr_remove(&battery_id, num);
> +	mutex_unlock(&battery_mutex);
> +
> +	return ret;
>  }
>  
>  static int bq27xxx_battery_i2c_remove(struct i2c_client *client)

Hi! Should not we call idr_remove() also in bq27xxx_battery_i2c_remove()?

-- 
Pali Rohár
pali.rohar@gmail.com

[toc] | [prev] | [next] | [standalone]


#1324037

FromIvaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
Date2016-02-02 13:40 +0100
Message-ID<qXIps-2Vl-1@gated-at.bofh.it>
In reply to#1324035

On  2.02.2016 14:27, Pali Rohár wrote:
>
> Hi! Should not we call idr_remove() also in bq27xxx_battery_i2c_remove()?
>

Yes, missed that code in the commit, I am sending the full version in a 
minute

[toc] | [prev] | [next] | [standalone]


#1324040 — Re: [PATCH v1] power: bq27xxx_battery: Restore device name

FromIvaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
Date2016-02-02 13:40 +0100
SubjectRe: [PATCH v1] power: bq27xxx_battery: Restore device name
Message-ID<qXIps-2Vl-11@gated-at.bofh.it>
In reply to#1324035
Guys, sorry for the noise, I got flue over my brain. This patch is 
broken too, will fix it and will resend.

On  2.02.2016 14:34, Ivaylo Dimitrov wrote:
> Patch <703df6c097956d17a818e63961c82e8e9eef9fef> ("power: bq27xxx_battery:
>   Reorganize I2C into a module") has removed the device name numbering from
> bq27xxx_battery_i2c_probe. Fix that by restoring the code.
>
> Signed-off-by: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
> ---
>   drivers/power/bq27xxx_battery_i2c.c | 36 +++++++++++++++++++++++++++++++++---
>   1 file changed, 33 insertions(+), 3 deletions(-)
>

[toc] | [prev] | [next] | [standalone]


#1324046 — [PATCH v2] power: bq27xxx_battery: Restore device name

FromIvaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
Date2016-02-02 13:50 +0100
Subject[PATCH v2] power: bq27xxx_battery: Restore device name
Message-ID<qXIz8-2Za-17@gated-at.bofh.it>
In reply to#1324040
Patch <703df6c097956d17a818e63961c82e8e9eef9fef> ("power: bq27xxx_battery:
 Reorganize I2C into a module") has removed the device name numbering from
bq27xxx_battery_i2c_probe. Fix that by restoring the code.

Signed-off-by: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
---
 drivers/power/bq27xxx_battery_i2c.c   | 37 ++++++++++++++++++++++++++++++++---
 include/linux/power/bq27xxx_battery.h |  1 +
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/drivers/power/bq27xxx_battery_i2c.c b/drivers/power/bq27xxx_battery_i2c.c
index b810e08..b8f8d3a 100644
--- a/drivers/power/bq27xxx_battery_i2c.c
+++ b/drivers/power/bq27xxx_battery_i2c.c
@@ -21,6 +21,9 @@
 
 #include <linux/power/bq27xxx_battery.h>
 
+static DEFINE_IDR(battery_id);
+static DEFINE_MUTEX(battery_mutex);
+
 static irqreturn_t bq27xxx_battery_irq_handler_thread(int irq, void *data)
 {
 	struct bq27xxx_device_info *di = data;
@@ -70,19 +73,33 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client,
 {
 	struct bq27xxx_device_info *di;
 	int ret;
+	char *name;
+	int num;
+
+	/* Get new ID for the new battery device */
+	mutex_lock(&battery_mutex);
+	num = idr_alloc(&battery_id, client, 0, 0, GFP_KERNEL);
+	mutex_unlock(&battery_mutex);
+	if (num < 0)
+		return num;
+
+	name = devm_kasprintf(&client->dev, GFP_KERNEL, "%s-%d", id->name, num);
+	if (!name)
+		goto err_mem;
 
 	di = devm_kzalloc(&client->dev, sizeof(*di), GFP_KERNEL);
 	if (!di)
-		return -ENOMEM;
+		goto err_mem;
 
+	di->id = num;
 	di->dev = &client->dev;
 	di->chip = id->driver_data;
-	di->name = id->name;
+	di->name = name;
 	di->bus.read = bq27xxx_battery_i2c_read;
 
 	ret = bq27xxx_battery_setup(di);
 	if (ret)
-		return ret;
+		goto err_failed;
 
 	/* Schedule a polling after about 1 min */
 	schedule_delayed_work(&di->work, 60 * HZ);
@@ -103,6 +120,16 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client,
 	}
 
 	return 0;
+
+err_mem:
+	ret = -ENOMEM;
+
+err_failed:
+	mutex_lock(&battery_mutex);
+	idr_remove(&battery_id, num);
+	mutex_unlock(&battery_mutex);
+
+	return ret;
 }
 
 static int bq27xxx_battery_i2c_remove(struct i2c_client *client)
@@ -111,6 +138,10 @@ static int bq27xxx_battery_i2c_remove(struct i2c_client *client)
 
 	bq27xxx_battery_teardown(di);
 
+	mutex_lock(&battery_mutex);
+	idr_remove(&battery_id, di->id);
+	mutex_unlock(&battery_mutex);
+
 	return 0;
 }
 
diff --git a/include/linux/power/bq27xxx_battery.h b/include/linux/power/bq27xxx_battery.h
index 998d8f1..b50c049 100644
--- a/include/linux/power/bq27xxx_battery.h
+++ b/include/linux/power/bq27xxx_battery.h
@@ -49,6 +49,7 @@ struct bq27xxx_reg_cache {
 
 struct bq27xxx_device_info {
 	struct device *dev;
+	int id;
 	enum bq27xxx_chip chip;
 	const char *name;
 	struct bq27xxx_access_methods bus;
-- 
1.9.1

[toc] | [prev] | [next] | [standalone]


#1328270 — Re: [PATCH v2] power: bq27xxx_battery: Restore device name

FromPali Rohár <pali.rohar@gmail.com>
Date2016-02-06 11:40 +0100
SubjectRe: [PATCH v2] power: bq27xxx_battery: Restore device name
Message-ID<qZ8rw-5W3-3@gated-at.bofh.it>
In reply to#1324046

[Multipart message — attachments visible in raw view] — view raw

On Tuesday 02 February 2016 13:47:37 Ivaylo Dimitrov wrote:
> Patch <703df6c097956d17a818e63961c82e8e9eef9fef> ("power:
> bq27xxx_battery: Reorganize I2C into a module") has removed the
> device name numbering from bq27xxx_battery_i2c_probe. Fix that by
> restoring the code.
> 
> Signed-off-by: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>

Fixes: 703df6c097956d17a818e63961c82e8e9eef9fef
Reviewed-by: Pali Rohár <pali.rohar@gmail.com>
Tested-by: Pali Rohár <pali.rohar@gmail.com>

Please apply this patch and backport to stable kernels with already has 
patch 703df6c097956d17a818e63961c82e8e9eef9fef.

-- 
Pali Rohár
pali.rohar@gmail.com

[toc] | [prev] | [next] | [standalone]


#1324041 — [PATCH v1] power: bq27xxx_battery: Restore device name

FromIvaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
Date2016-02-02 13:40 +0100
Subject[PATCH v1] power: bq27xxx_battery: Restore device name
Message-ID<qXIps-2Vl-13@gated-at.bofh.it>
In reply to#1324035
Patch <703df6c097956d17a818e63961c82e8e9eef9fef> ("power: bq27xxx_battery:
 Reorganize I2C into a module") has removed the device name numbering from
bq27xxx_battery_i2c_probe. Fix that by restoring the code.

Signed-off-by: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
---
 drivers/power/bq27xxx_battery_i2c.c | 36 +++++++++++++++++++++++++++++++++---
 1 file changed, 33 insertions(+), 3 deletions(-)

diff --git a/drivers/power/bq27xxx_battery_i2c.c b/drivers/power/bq27xxx_battery_i2c.c
index b810e08..6b4a7cf 100644
--- a/drivers/power/bq27xxx_battery_i2c.c
+++ b/drivers/power/bq27xxx_battery_i2c.c
@@ -21,6 +21,9 @@
 
 #include <linux/power/bq27xxx_battery.h>
 
+static DEFINE_IDR(battery_id);
+static DEFINE_MUTEX(battery_mutex);
+
 static irqreturn_t bq27xxx_battery_irq_handler_thread(int irq, void *data)
 {
 	struct bq27xxx_device_info *di = data;
@@ -70,19 +73,32 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client,
 {
 	struct bq27xxx_device_info *di;
 	int ret;
+	char *name;
+	int num;
+
+	/* Get new ID for the new battery device */
+	mutex_lock(&battery_mutex);
+	num = idr_alloc(&battery_id, client, 0, 0, GFP_KERNEL);
+	mutex_unlock(&battery_mutex);
+	if (num < 0)
+		return num;
+
+	name = devm_kasprintf(&client->dev, GFP_KERNEL, "%s-%d", id->name, num);
+	if (!name)
+		goto err_mem;
 
 	di = devm_kzalloc(&client->dev, sizeof(*di), GFP_KERNEL);
 	if (!di)
-		return -ENOMEM;
+		goto err_mem;
 
 	di->dev = &client->dev;
 	di->chip = id->driver_data;
-	di->name = id->name;
+	di->name = name;
 	di->bus.read = bq27xxx_battery_i2c_read;
 
 	ret = bq27xxx_battery_setup(di);
 	if (ret)
-		return ret;
+		goto err_failed;
 
 	/* Schedule a polling after about 1 min */
 	schedule_delayed_work(&di->work, 60 * HZ);
@@ -103,6 +119,16 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client,
 	}
 
 	return 0;
+
+err_mem:
+	ret = -ENOMEM;
+
+err_failed:
+	mutex_lock(&battery_mutex);
+	idr_remove(&battery_id, num);
+	mutex_unlock(&battery_mutex);
+
+	return ret;
 }
 
 static int bq27xxx_battery_i2c_remove(struct i2c_client *client)
@@ -111,6 +137,10 @@ static int bq27xxx_battery_i2c_remove(struct i2c_client *client)
 
 	bq27xxx_battery_teardown(di);
 
+	mutex_lock(&battery_mutex);
+	idr_remove(&battery_id, num);
+	mutex_unlock(&battery_mutex);
+
 	return 0;
 }
 
-- 
1.9.1

[toc] | [prev] | [next] | [standalone]


#1324043 — Re: [PATCH v1] power: bq27xxx_battery: Restore device name

Fromkbuild test robot <lkp@intel.com>
Date2016-02-02 13:50 +0100
SubjectRe: [PATCH v1] power: bq27xxx_battery: Restore device name
Message-ID<qXIz8-2Za-7@gated-at.bofh.it>
In reply to#1324041

[Multipart message — attachments visible in raw view] — view raw

Hi Ivaylo,

[auto build test ERROR on battery/master]
[also build test ERROR on v4.5-rc2 next-20160201]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Ivaylo-Dimitrov/power-bq27xxx_battery-Restore-device-name/20160202-203646
base:   git://git.infradead.org/battery-2.6.git master
config: i386-randconfig-x003-02010231 (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

   drivers/power/bq27xxx_battery_i2c.c: In function 'bq27xxx_battery_i2c_remove':
>> drivers/power/bq27xxx_battery_i2c.c:141:26: error: 'num' undeclared (first use in this function)
     idr_remove(&battery_id, num);
                             ^
   drivers/power/bq27xxx_battery_i2c.c:141:26: note: each undeclared identifier is reported only once for each function it appears in

vim +/num +141 drivers/power/bq27xxx_battery_i2c.c

   135	{
   136		struct bq27xxx_device_info *di = i2c_get_clientdata(client);
   137	
   138		bq27xxx_battery_teardown(di);
   139	
   140		mutex_lock(&battery_mutex);
 > 141		idr_remove(&battery_id, num);
   142		mutex_unlock(&battery_mutex);
   143	
   144		return 0;

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web