Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

regulator: core: Fix size limit of supply_map

Now the debugfs file supply_map has a size limit PAGE_SIZE and the user
can not see the whole content of regulator_map_list when it is larger
than this limit.

This patch uses seq_file instead to make sure supply_map shows the full
information of regulator_map_list.

Signed-off-by: Haishan Zhou <zhssmail@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Haishan Zhou and committed by
Mark Brown
dbc55955 06217197

+13 -23
+13 -23
drivers/regulator/core.c
··· 4311 4311 EXPORT_SYMBOL_GPL(regulator_get_init_drvdata); 4312 4312 4313 4313 #ifdef CONFIG_DEBUG_FS 4314 - static ssize_t supply_map_read_file(struct file *file, char __user *user_buf, 4315 - size_t count, loff_t *ppos) 4314 + static int supply_map_show(struct seq_file *sf, void *data) 4316 4315 { 4317 - char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 4318 - ssize_t len, ret = 0; 4319 4316 struct regulator_map *map; 4320 4317 4321 - if (!buf) 4322 - return -ENOMEM; 4323 - 4324 4318 list_for_each_entry(map, &regulator_map_list, list) { 4325 - len = snprintf(buf + ret, PAGE_SIZE - ret, 4326 - "%s -> %s.%s\n", 4327 - rdev_get_name(map->regulator), map->dev_name, 4328 - map->supply); 4329 - if (len >= 0) 4330 - ret += len; 4331 - if (ret > PAGE_SIZE) { 4332 - ret = PAGE_SIZE; 4333 - break; 4334 - } 4319 + seq_printf(sf, "%s -> %s.%s\n", 4320 + rdev_get_name(map->regulator), map->dev_name, 4321 + map->supply); 4335 4322 } 4336 4323 4337 - ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); 4324 + return 0; 4325 + } 4338 4326 4339 - kfree(buf); 4340 - 4341 - return ret; 4327 + static int supply_map_open(struct inode *inode, struct file *file) 4328 + { 4329 + return single_open(file, supply_map_show, inode->i_private); 4342 4330 } 4343 4331 #endif 4344 4332 4345 4333 static const struct file_operations supply_map_fops = { 4346 4334 #ifdef CONFIG_DEBUG_FS 4347 - .read = supply_map_read_file, 4348 - .llseek = default_llseek, 4335 + .open = supply_map_open, 4336 + .read = seq_read, 4337 + .llseek = seq_lseek, 4338 + .release = single_release, 4349 4339 #endif 4350 4340 }; 4351 4341