Skip to contentSkip to conversation

regmap: Remove bitrotted module_put()s

PATCH In review Mark Brown 2 participants 4 messages Sep 5, 2011

Subsystems (2)
lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/3 regmap: Remove bitrotted module_put()s

The conversion to per bus type registration functions means we don't need to do module_get()s to hold the bus types in memory (their users will link to them) so we removed all those calls. This left module_put() calls in the cleanup paths which aren't needed and which cause unbalanced puts if we ever try to unload anything.

---
 drivers/base/regmap/regmap.c |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)
drivers/base/regmap/regmap.c +1 -4
index fa2bd89..86b1847 100644
@@ -198,15 +198,13 @@ struct regmap *regmap_init(struct device *dev,
 	map->work_buf = kmalloc(map->format.buf_size, GFP_KERNEL);
 	if (map->work_buf == NULL) {
 		ret = -ENOMEM;
-		goto err_bus;
+		goto err_map;
 	}
 
 	regmap_debugfs_init(map);
 
 	return map;
 
-err_bus:
-	module_put(map->bus->owner);
 err_map:
 	kfree(map);
 err:
@@ -221,7 +219,6 @@ void regmap_exit(struct regmap *map)
 {
 	regmap_debugfs_exit(map);
 	kfree(map->work_buf);
-	module_put(map->bus->owner);
 	kfree(map);
 }
 EXPORT_SYMBOL_GPL(regmap_exit);
Signature · 1 line
1.7.5.4
author
#1 lore raw

PATCH 2/3 regmap: Remove redundant owner field from the bus type struct

No longer used as users link directly with the bus types so the core module infrastructure does refcounting for us.

---
 drivers/base/regmap/regmap-i2c.c |    1 -
 drivers/base/regmap/regmap-spi.c |    1 -
 include/linux/regmap.h           |    3 ---
 3 files changed, 0 insertions(+), 5 deletions(-)
drivers/base/regmap/regmap-i2c.c +0 -1
index e7d916d..38621ec 100644
@@ -93,7 +93,6 @@ static struct regmap_bus regmap_i2c = {
 	.write = regmap_i2c_write,
 	.gather_write = regmap_i2c_gather_write,
 	.read = regmap_i2c_read,
-	.owner = THIS_MODULE,
 };
 
 /**
drivers/base/regmap/regmap-spi.c +0 -1
index fe831e3..2560658 100644
@@ -51,7 +51,6 @@ static struct regmap_bus regmap_spi = {
 	.write = regmap_spi_write,
 	.gather_write = regmap_spi_gather_write,
 	.read = regmap_spi_read,
-	.owner = THIS_MODULE,
 	.read_flag_mask = 0x80,
 };
 
include/linux/regmap.h +0 -3
index 449e264..9438a89e 100644
@@ -85,8 +85,6 @@ typedef int (*regmap_hw_read)(struct device *dev,
  *                if not implemented  on a given device.
  * @read: Read operation.  Data is returned in the buffer used to transmit
  *         data.
- * @owner: Module with the bus implementation, used to pin the implementation
- *         in memory.
  * @read_flag_mask: Mask to be set in the top byte of the register when doing
  *                  a read.
  */
@@ -94,7 +92,6 @@ struct regmap_bus {
 	regmap_hw_write write;
 	regmap_hw_gather_write gather_write;
 	regmap_hw_read read;
-	struct module *owner;
 	u8 read_flag_mask;
 };
 
Signature · 1 line
1.7.5.4
author
#2 lore raw

PATCH 3/3 regmap: Include the last register in debugfs output

In reply to Mark Brown

Off by one in the array iteration.

---
 drivers/base/regmap/regmap-debugfs.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/base/regmap/regmap-debugfs.c +2 -2
index 7a8d675..6f39747 100644
@@ -57,7 +57,7 @@ static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf,
 	val_len = 2 * map->format.val_bytes;
 	tot_len = reg_len + val_len + 3;      /* : \n */
 
-	for (i = 0; i < map->max_register; i++) {
+	for (i = 0; i < map->max_register + 1; i++) {
 		if (!regmap_readable(map, i))
 			continue;
 
@@ -132,7 +132,7 @@ static ssize_t regmap_access_read_file(struct file *file,
 	reg_len = regmap_calc_reg_len(map->max_register, buf, count);
 	tot_len = reg_len + 10; /* ': R W V P\n' */
 
-	for (i = 0; i < map->max_register; i++) {
+	for (i = 0; i < map->max_register + 1; i++) {
 		/* Ignore registers which are neither readable nor writable */
 		if (!regmap_readable(map, i) && !regmap_writeable(map, i))
 			continue;
Signature · 1 line
1.7.5.4
#3 lore raw
In reply to Mark Brown
Quoted 6 lines · Mark Brown

The conversion to per bus type registration functions means we don't need to do module_get()s to hold the bus types in memory (their users will link to them) so we removed all those calls. This left module_put() calls in the cleanup paths which aren't needed and which cause unbalanced puts if we ever try to unload anything.

Thanks Mark, all three look good to me. Thanks also for your comments on my driver changes, I'll clean it up and repost tomorrow.

Quoted 36 lines

drivers/base/regmap/regmap.c | 5 +----

1 files changed, 1 insertions(+), 4 deletions(-)
drivers/base/regmap/regmap.c +1 -3
index fa2bd89..86b1847 100644
@@ -198,15 +198,13 @@ struct regmap *regmap_init(struct device *dev,
 	map->work_buf = kmalloc(map->format.buf_size, GFP_KERNEL);
 	if (map->work_buf == NULL) {
 		ret = -ENOMEM;
-		goto err_bus;
+		goto err_map;
 	}
 
 	regmap_debugfs_init(map);
 
 	return map;
 
-err_bus:
-	module_put(map->bus->owner);

err_map:

	kfree(map);

err:

drivers/base/regmap/regmap.c +0 -1
@@ -221,7 +219,6 @@ void regmap_exit(struct regmap *map)
 {
 	regmap_debugfs_exit(map);
 	kfree(map->work_buf);
-	module_put(map->bus->owner);
 	kfree(map);
 }
 EXPORT_SYMBOL_GPL(regmap_exit);