diff mbox

i2c: sun6-p2wi: fix call to snprintf

Message ID 1402644002-2591-1-git-send-email-boris.brezillon@free-electrons.com (mailing list archive)
State New, archived
Headers show

Commit Message

Boris BREZILLON June 13, 2014, 7:20 a.m. UTC
Fixes possible issue in case pdev name contains formatting characters.

Signed-off-by: Boris BREZILLON <boris.brezillon@free-electrons.com>
Reported-by: Kees Cook <keescook@google.com>
---
 drivers/i2c/busses/i2c-sun6i-p2wi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Russell King - ARM Linux June 13, 2014, 9:57 a.m. UTC | #1
On Fri, Jun 13, 2014 at 09:20:02AM +0200, Boris BREZILLON wrote:
> -	snprintf(p2wi->adapter.name, sizeof(p2wi->adapter.name), pdev->name);
> +	snprintf(p2wi->adapter.name, sizeof(p2wi->adapter.name), "%s",
> +		 pdev->name);

Isn't this just a complicated way to express:

	strlcpy(p2wi->adapter.name, pdev->name, sizeof(p2wi->adapter.name));

?
Boris BREZILLON June 13, 2014, 10:09 a.m. UTC | #2
On 13/06/2014 11:57, Russell King - ARM Linux wrote:
> On Fri, Jun 13, 2014 at 09:20:02AM +0200, Boris BREZILLON wrote:
>> -	snprintf(p2wi->adapter.name, sizeof(p2wi->adapter.name), pdev->name);
>> +	snprintf(p2wi->adapter.name, sizeof(p2wi->adapter.name), "%s",
>> +		 pdev->name);
> Isn't this just a complicated way to express:
>
> 	strlcpy(p2wi->adapter.name, pdev->name, sizeof(p2wi->adapter.name));
>
> ?

Yes it is. I'll make use of strlcpy instead.

Thanks,

Boris
diff mbox

Patch

diff --git a/drivers/i2c/busses/i2c-sun6i-p2wi.c b/drivers/i2c/busses/i2c-sun6i-p2wi.c
index 5d2d678..63d1b2d 100644
--- a/drivers/i2c/busses/i2c-sun6i-p2wi.c
+++ b/drivers/i2c/busses/i2c-sun6i-p2wi.c
@@ -237,7 +237,8 @@  static int p2wi_probe(struct platform_device *pdev)
 	if (IS_ERR(p2wi->regs))
 		return PTR_ERR(p2wi->regs);
 
-	snprintf(p2wi->adapter.name, sizeof(p2wi->adapter.name), pdev->name);
+	snprintf(p2wi->adapter.name, sizeof(p2wi->adapter.name), "%s",
+		 pdev->name);
 	irq = platform_get_irq(pdev, 0);
 	if (irq < 0) {
 		dev_err(dev, "failed to retrieve irq: %d\n", irq);