From patchwork Fri Oct 26 23:24:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 10657981 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AE45614E2 for ; Fri, 26 Oct 2018 23:24:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A04E82CC3A for ; Fri, 26 Oct 2018 23:24:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 945112CC78; Fri, 26 Oct 2018 23:24:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A4DB2CC3A for ; Fri, 26 Oct 2018 23:24:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728935AbeJ0ID3 (ORCPT ); Sat, 27 Oct 2018 04:03:29 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:33076 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728878AbeJ0IDU (ORCPT ); Sat, 27 Oct 2018 04:03:20 -0400 Received: by mail-ed1-f67.google.com with SMTP id f1-v6so2664858edi.0 for ; Fri, 26 Oct 2018 16:24:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cUV4UhVcG/AakGqgG1SR2fwK+v1//1QwRiJOscTtP5E=; b=BXS3VRB1j+OTug557fp1po0BE+SAyb1vYONJzOY81tpn1zNnPVsLnzKKQoHdWLdgUu UCx8YbF6UAWxs/+LFDtgnOxPTtGkxGvLhguO46GLUdSLXGKGofzvVjp/HxP8UXo6ySHn q9sRjIRAmSZzJDq7uGtuiQpRLskXWVrMClXQc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cUV4UhVcG/AakGqgG1SR2fwK+v1//1QwRiJOscTtP5E=; b=M/Itn/Trds98P/3j2h85n7q1YjhKzybB8qLImYp1VBwqni3FJzRlmJUxDPMEdalVuc 0hq9CqAZq0eutQbMSs12/Fqt7ZblpryjLXu5FvSHxYnIfOZrIC0dnn6Dy8zkcjbeKozt tGu1NPsiPKJFA0HHylfEDt4SUQsqax3wZZXuT6BWF4gwPVQkKMD9+VKiFWk4srrEdL9M Z9MGkFrFdjFE4fVLNMcAVSqjqbzqloVGc6cgeUYBRO8ANevsJg/bZR7yb3MF1kx9nDFc n+9h4Wc0wXCOcq3CRliAyl+qaeH/MXMDq4PX/thwoMQmgdq9ML0nZctQ649Ul379fSov 4FGg== X-Gm-Message-State: AGRZ1gIOPG96I/DfwOtkAQH5bgZwnHCFwPzYKbMDNN0777hW/GfA43Fm DzAvtz2OWGAz9oNXNRMmYOLS1g== X-Google-Smtp-Source: AJdET5dfrxWw6PmGhxwmYYnOaNlHN0yHQoG1SS8x3O4MqKpbLxZRgPFGiRJUaIFg5u61DOxX8H6gKA== X-Received: by 2002:a50:9724:: with SMTP id c33-v6mr4602757edb.47.1540596260146; Fri, 26 Oct 2018 16:24:20 -0700 (PDT) Received: from prevas-ravi.waoo.dk (dhcp-5-186-114-252.cgn.ip.fibianet.dk. [5.186.114.252]) by smtp.gmail.com with ESMTPSA id o13-v6sm3986746edc.95.2018.10.26.16.24.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Oct 2018 16:24:19 -0700 (PDT) From: Rasmus Villemoes To: Kees Cook , Andrew Morton , Jean Delvare , Guenter Roeck Cc: linux-kernel@vger.kernel.org, Rasmus Villemoes , linux-hwmon@vger.kernel.org Subject: [RFC PATCH 7/7] drivers: hwmon: add runtime format string checking Date: Sat, 27 Oct 2018 01:24:09 +0200 Message-Id: <20181026232409.16100-8-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.19.1.6.gbde171bbf5 In-Reply-To: <20181026232409.16100-1-linux@rasmusvillemoes.dk> References: <20171108223020.24487-1-linux@rasmusvillemoes.dk> <20181026232409.16100-1-linux@rasmusvillemoes.dk> MIME-Version: 1.0 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP With -Wformat-nonliteral, gcc complains drivers/hwmon/hwmon.c: In function ‘hwmon_genattr’: drivers/hwmon/hwmon.c:282:6: warning: format not a string literal, argument types not checked [-Wformat-nonliteral] index + hwmon_attr_base(type)); Add a runtime check to ensure that the template indeed has a single %d printf specifier. Using fmtcheck() also makes gcc verify that the expression 'index + hwmon_attr_base(type)' is suitable for %d. Signed-off-by: Rasmus Villemoes --- drivers/hwmon/hwmon.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c index 33d51281272b..ec6f5f36b5fc 100644 --- a/drivers/hwmon/hwmon.c +++ b/drivers/hwmon/hwmon.c @@ -278,7 +278,8 @@ static struct attribute *hwmon_genattr(struct device *dev, if (type == hwmon_chip) { name = (char *)template; } else { - scnprintf(hattr->name, sizeof(hattr->name), template, + scnprintf(hattr->name, sizeof(hattr->name), + fmtcheck(template, "type%dwhat", 0), index + hwmon_attr_base(type)); name = hattr->name; }