Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754525AbdCFQfE (ORCPT ); Mon, 6 Mar 2017 11:35:04 -0500 Received: from mail-wm0-f41.google.com ([74.125.82.41]:33035 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754497AbdCFQex (ORCPT ); Mon, 6 Mar 2017 11:34:53 -0500 From: Bartosz Golaszewski To: Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH] regulator: core: use snprintf() instead of scnprintf() Date: Mon, 6 Mar 2017 17:34:48 +0100 Message-Id: <1488818088-3588-1-git-send-email-bgolaszewski@baylibre.com> X-Mailer: git-send-email 2.1.4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1082 Lines: 32 When creating the link to the device sysfs entry, the regulator core calls scnprintf() and then checks if the returned value is greater or equal than the buffer size. The former can never happen as scnprintf() returns the number of bytes that were actually written to the buffer, not the bytes that *would* have been written. Use the right function in this case: snprintf(). Signed-off-by: Bartosz Golaszewski --- drivers/regulator/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 53d4fc7..f20ad0a 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1326,8 +1326,8 @@ static struct regulator *create_regulator(struct regulator_dev *rdev, regulator->dev = dev; /* Add a link to the device sysfs entry */ - size = scnprintf(buf, REG_STR_SIZE, "%s-%s", - dev->kobj.name, supply_name); + size = snprintf(buf, REG_STR_SIZE, "%s-%s", + dev->kobj.name, supply_name); if (size >= REG_STR_SIZE) goto overflow_err; -- 2.9.3