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

Configure Feed

Select the types of activity you want to include in your feed.

firmware: cs_dsp: Cleanup debugfs for wmfw and bin

Merge series from Richard Fitzgerald <rf@opensource.cirrus.com>:

These two patches improve the implementation of the debugfs files for
the wmfw and bin file names. First patch removes duplicated code. Second
patch replaces the old clunkiness of storing the filename with an appended
\n. The \n can be appended when the file is read, to keep the stored string
sane.

+28 -32
+26 -30
drivers/firmware/cirrus/cs_dsp.c
··· 9 9 * Cirrus Logic International Semiconductor Ltd. 10 10 */ 11 11 12 + #include <linux/cleanup.h> 12 13 #include <linux/ctype.h> 13 14 #include <linux/debugfs.h> 14 15 #include <linux/delay.h> ··· 389 388 #ifdef CONFIG_DEBUG_FS 390 389 static void cs_dsp_debugfs_save_wmfwname(struct cs_dsp *dsp, const char *s) 391 390 { 392 - char *tmp = kasprintf(GFP_KERNEL, "%s\n", s); 393 - 394 391 kfree(dsp->wmfw_file_name); 395 - dsp->wmfw_file_name = tmp; 392 + dsp->wmfw_file_name = kstrdup(s, GFP_KERNEL); 396 393 } 397 394 398 395 static void cs_dsp_debugfs_save_binname(struct cs_dsp *dsp, const char *s) 399 396 { 400 - char *tmp = kasprintf(GFP_KERNEL, "%s\n", s); 401 - 402 397 kfree(dsp->bin_file_name); 403 - dsp->bin_file_name = tmp; 398 + dsp->bin_file_name = kstrdup(s, GFP_KERNEL); 404 399 } 405 400 406 401 static void cs_dsp_debugfs_clear(struct cs_dsp *dsp) ··· 407 410 dsp->bin_file_name = NULL; 408 411 } 409 412 413 + static ssize_t cs_dsp_debugfs_string_read(struct cs_dsp *dsp, 414 + char __user *user_buf, 415 + size_t count, loff_t *ppos, 416 + const char **pstr) 417 + { 418 + const char *str __free(kfree) = NULL; 419 + 420 + scoped_guard(mutex, &dsp->pwr_lock) { 421 + if (!*pstr) 422 + return 0; 423 + 424 + str = kasprintf(GFP_KERNEL, "%s\n", *pstr); 425 + if (!str) 426 + return -ENOMEM; 427 + 428 + return simple_read_from_buffer(user_buf, count, ppos, str, strlen(str)); 429 + } 430 + } 431 + 410 432 static ssize_t cs_dsp_debugfs_wmfw_read(struct file *file, 411 433 char __user *user_buf, 412 434 size_t count, loff_t *ppos) 413 435 { 414 436 struct cs_dsp *dsp = file->private_data; 415 - ssize_t ret; 416 437 417 - mutex_lock(&dsp->pwr_lock); 418 - 419 - if (!dsp->wmfw_file_name || !dsp->booted) 420 - ret = 0; 421 - else 422 - ret = simple_read_from_buffer(user_buf, count, ppos, 423 - dsp->wmfw_file_name, 424 - strlen(dsp->wmfw_file_name)); 425 - 426 - mutex_unlock(&dsp->pwr_lock); 427 - return ret; 438 + return cs_dsp_debugfs_string_read(dsp, user_buf, count, ppos, 439 + &dsp->wmfw_file_name); 428 440 } 429 441 430 442 static ssize_t cs_dsp_debugfs_bin_read(struct file *file, ··· 441 435 size_t count, loff_t *ppos) 442 436 { 443 437 struct cs_dsp *dsp = file->private_data; 444 - ssize_t ret; 445 438 446 - mutex_lock(&dsp->pwr_lock); 447 - 448 - if (!dsp->bin_file_name || !dsp->booted) 449 - ret = 0; 450 - else 451 - ret = simple_read_from_buffer(user_buf, count, ppos, 452 - dsp->bin_file_name, 453 - strlen(dsp->bin_file_name)); 454 - 455 - mutex_unlock(&dsp->pwr_lock); 456 - return ret; 439 + return cs_dsp_debugfs_string_read(dsp, user_buf, count, ppos, 440 + &dsp->bin_file_name); 457 441 } 458 442 459 443 static const struct {
+2 -2
include/linux/firmware/cirrus/cs_dsp.h
··· 188 188 189 189 #ifdef CONFIG_DEBUG_FS 190 190 struct dentry *debugfs_root; 191 - char *wmfw_file_name; 192 - char *bin_file_name; 191 + const char *wmfw_file_name; 192 + const char *bin_file_name; 193 193 #endif 194 194 }; 195 195