aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2016-01-25 19:21:26 -0500
committerRussell King <rmk+kernel@arm.linux.org.uk>2016-02-16 11:34:18 -0500
commit416dd13ad620a14fbabe5d73584b12e07ce8d02e (patch)
treefb0833d4e38e932c5617ed5dd13db75a1fac593b
parenta34c66357e1328fef6388ef6e10ce67275f5f5fe (diff)
ARM: 8503/1: clk_register_clkdev: remove format string interface
Many callers either use NULL or const strings for the third argument of clk_register_clkdev. For those that do not and use a non-const string, this is a risk for format strings being accidentally processed (for example in device names). As this interface is already used as if it weren't a format string (prints nothing when NULL), and there are zero users of the format strings, remove the format string interface to make sure format strings will not leak into the clkdev. $ git grep '\bclk_register_clkdev\b' | grep % | wc -l 0 Unfortunately, all the internals expect a va_list even though they treat a NULL format string as special. To deal with this, we must pass either (..., "%s", string) or (..., NULL) so that a the va_list will be created correctly (passing the name as an argument, not as a format string). Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
-rw-r--r--drivers/clk/clkdev.c31
-rw-r--r--include/linux/clkdev.h3
2 files changed, 26 insertions, 8 deletions
diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
index 779b6ff0c7ad..eb20b941154b 100644
--- a/drivers/clk/clkdev.c
+++ b/drivers/clk/clkdev.c
@@ -353,11 +353,25 @@ void clkdev_drop(struct clk_lookup *cl)
353} 353}
354EXPORT_SYMBOL(clkdev_drop); 354EXPORT_SYMBOL(clkdev_drop);
355 355
356static struct clk_lookup *__clk_register_clkdev(struct clk_hw *hw,
357 const char *con_id,
358 const char *dev_id, ...)
359{
360 struct clk_lookup *cl;
361 va_list ap;
362
363 va_start(ap, dev_id);
364 cl = vclkdev_create(hw, con_id, dev_id, ap);
365 va_end(ap);
366
367 return cl;
368}
369
356/** 370/**
357 * clk_register_clkdev - register one clock lookup for a struct clk 371 * clk_register_clkdev - register one clock lookup for a struct clk
358 * @clk: struct clk to associate with all clk_lookups 372 * @clk: struct clk to associate with all clk_lookups
359 * @con_id: connection ID string on device 373 * @con_id: connection ID string on device
360 * @dev_id: format string describing device name 374 * @dev_id: string describing device name
361 * 375 *
362 * con_id or dev_id may be NULL as a wildcard, just as in the rest of 376 * con_id or dev_id may be NULL as a wildcard, just as in the rest of
363 * clkdev. 377 * clkdev.
@@ -368,17 +382,22 @@ EXPORT_SYMBOL(clkdev_drop);
368 * after clk_register(). 382 * after clk_register().
369 */ 383 */
370int clk_register_clkdev(struct clk *clk, const char *con_id, 384int clk_register_clkdev(struct clk *clk, const char *con_id,
371 const char *dev_fmt, ...) 385 const char *dev_id)
372{ 386{
373 struct clk_lookup *cl; 387 struct clk_lookup *cl;
374 va_list ap;
375 388
376 if (IS_ERR(clk)) 389 if (IS_ERR(clk))
377 return PTR_ERR(clk); 390 return PTR_ERR(clk);
378 391
379 va_start(ap, dev_fmt); 392 /*
380 cl = vclkdev_create(__clk_get_hw(clk), con_id, dev_fmt, ap); 393 * Since dev_id can be NULL, and NULL is handled specially, we must
381 va_end(ap); 394 * pass it as either a NULL format string, or with "%s".
395 */
396 if (dev_id)
397 cl = __clk_register_clkdev(__clk_get_hw(clk), con_id, "%s",
398 dev_id);
399 else
400 cl = __clk_register_clkdev(__clk_get_hw(clk), con_id, NULL);
382 401
383 return cl ? 0 : -ENOMEM; 402 return cl ? 0 : -ENOMEM;
384} 403}
diff --git a/include/linux/clkdev.h b/include/linux/clkdev.h
index 08bffcc466de..c2c04f7cbe8a 100644
--- a/include/linux/clkdev.h
+++ b/include/linux/clkdev.h
@@ -44,8 +44,7 @@ struct clk_lookup *clkdev_create(struct clk *clk, const char *con_id,
44void clkdev_add_table(struct clk_lookup *, size_t); 44void clkdev_add_table(struct clk_lookup *, size_t);
45int clk_add_alias(const char *, const char *, const char *, struct device *); 45int clk_add_alias(const char *, const char *, const char *, struct device *);
46 46
47int clk_register_clkdev(struct clk *, const char *, const char *, ...) 47int clk_register_clkdev(struct clk *, const char *, const char *);
48 __printf(3, 4);
49int clk_register_clkdevs(struct clk *, struct clk_lookup *, size_t); 48int clk_register_clkdevs(struct clk *, struct clk_lookup *, size_t);
50 49
51#ifdef CONFIG_COMMON_CLK 50#ifdef CONFIG_COMMON_CLK