From patchwork Mon Sep 27 10:14:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 514674 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp3962220jao; Mon, 27 Sep 2021 03:14:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJya5TUEo6AyqA32TJkd3XrWCmMqEkK53kOVJ38l8avkcBHy0NkGyXGFNZ/jTLAOXy1ICjeh X-Received: by 2002:a17:90a:5a07:: with SMTP id b7mr11372418pjd.196.1632737661693; Mon, 27 Sep 2021 03:14:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632737661; cv=none; d=google.com; s=arc-20160816; b=R0AXJ2wFHvDTDDB2Hl4pffko/YGlMz6eVGvIwIclN0H/VTQJVn1xPdEuHnSXoxD+zP iatySImqhDvbsW7WTURlIhPN8sJL9xm4Cli04qL7uol+W2iOC3tt/ThHZM4XhDHcrGIz s3hXOwB+gyY2fhQmE5U/a/Z5kAqKQHMax9Oevi7u0UIHJ5Onfkzwmdz6l3P9LMvm7+jC md6cP1DM4hvzpFOETqAIk+g8gvui4s1JDYoHFX4ukPyUHptqhVowTjSke6x6aA4iMfjw wudAIoDtZGPWeex+3hrfSftkB1CmGEWoUCNqPEk7LEWR+2jvlNjD3QCLXUjckrXGYl01 aFng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=aAulnS2nOTnr/ENadYZeh2MdvRexPEM8NvvHtWQf76c=; b=gWawFfEdup9vBZ91Fl6LQmQJfNR6FdOsfmGtfqIloCl5DuPxczv5g6K60H/OyDqMXG Up1NejZ5fKRViBEO4sb095h2GoCCBM1J4aYr6i+WVCakBkmgTghIUYXpmgxNvXD41z45 oPDIJqJbrME5nHpsxQ2RoKDdRtPikTX3WAv/OPYADgCmS8asggI4vEiafY+EA1as1c7I tJiWk7hEwaSD995b8z+Uu18QkrbGaRWaeiJFibHfKEruwOFHWTybWIyYwEjyP90ltY2o hBsd/hsfRjbi3t8YvbV46yATBMUeSTrkcbsSJt0xQ+IIrQYx1KACXYXXDeCZWo7ZzdL8 t2lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="pwP/fHyc"; spf=pass (google.com: domain of linux-input-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-input-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q2si18736403plr.447.2021.09.27.03.14.21; Mon, 27 Sep 2021 03:14:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-input-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="pwP/fHyc"; spf=pass (google.com: domain of linux-input-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-input-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233747AbhI0KP6 (ORCPT + 1 other); Mon, 27 Sep 2021 06:15:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:60310 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233703AbhI0KP5 (ORCPT ); Mon, 27 Sep 2021 06:15:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 94FF660F6C; Mon, 27 Sep 2021 10:14:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632737660; bh=mQhnijdLqalY6BhsW7eBN2/4Zqalyq0/oAzdB9fhxpw=; h=From:To:Cc:Subject:Date:From; b=pwP/fHycrsr3Pw+INmwN7VNZ7svNlULMbq5Q1/55NzymbXrI+Tt1xAeDk4Hp3alJI DM7Un9tKXDNMiXNaPbnQKDjG3s5M3P5I4ZkLNFQX4nDSnbPGKAt5KevuW4SIhIY/dY g/fhCJTNl86QA45tttBl1XaYWHAOHj2lHDSz1Y/MvPer9/OBksaoRFfcdRpuUQaIUA Dd0jy0XTq+HL/jd6CrZKLFbNP6mdAIlxov1jrZ3TB3U3gD0mHWlb3jVi+D88Io844N LZbNSu1kgrxy9YW2+86B/2vohOe2qv+nCIIYxTmtSvgYU1Ksh5RP1Vtsj/kSZybEA8 Iurt42xiTmYPw== From: Arnd Bergmann To: Dmitry Torokhov Cc: Arnd Bergmann , Rasmus Villemoes , Randy Dunlap , Zhang Qilong , Geert Uytterhoeven , Guenter Roeck , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] [RESEND] [v2] Input: analog - fix invalid snprintf() call Date: Mon, 27 Sep 2021 12:14:06 +0200 Message-Id: <20210927101416.1569609-1-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Arnd Bergmann Overlapping input and output arguments to snprintf() are undefined behavior in C99: drivers/input/joystick/analog.c: In function 'analog_name': drivers/input/joystick/analog.c:428:3: error: 'snprintf' argument 4 overlaps destination object 'analog' [-Werror=restrict] 428 | snprintf(analog->name, sizeof(analog->name), "%s %d-hat", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 429 | analog->name, hweight16(analog->mask & ANALOG_HATS_ALL)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/input/joystick/analog.c:420:40: note: destination object referenced by 'restrict'-qualified argument 1 was declared here 420 | static void analog_name(struct analog *analog) | ~~~~~~~~~~~~~~~^~~~~~ Change this function to use the simpler seq_buf interface instead. Cc: Rasmus Villemoes Link: https://lore.kernel.org/all/20210323131456.2600132-1-arnd@kernel.org/ Link: https://lore.kernel.org/all/20210324131959.2089129-1-arnd@kernel.org/ Signed-off-by: Arnd Bergmann --- v2: use seq_buf instead of rolling my own Resending as the second submission somehow got dropped --- drivers/input/joystick/analog.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) -- 2.29.2 diff --git a/drivers/input/joystick/analog.c b/drivers/input/joystick/analog.c index 882c3c8ba399..3c17bf202af5 100644 --- a/drivers/input/joystick/analog.c +++ b/drivers/input/joystick/analog.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -338,23 +339,24 @@ static void analog_calibrate_timer(struct analog_port *port) static void analog_name(struct analog *analog) { - snprintf(analog->name, sizeof(analog->name), "Analog %d-axis %d-button", + struct seq_buf s; + + seq_buf_init(&s, analog->name, sizeof(analog->name)); + seq_buf_printf(&s, "Analog %d-axis %d-button", hweight8(analog->mask & ANALOG_AXES_STD), hweight8(analog->mask & ANALOG_BTNS_STD) + !!(analog->mask & ANALOG_BTNS_CHF) * 2 + hweight16(analog->mask & ANALOG_BTNS_GAMEPAD) + !!(analog->mask & ANALOG_HBTN_CHF) * 4); if (analog->mask & ANALOG_HATS_ALL) - snprintf(analog->name, sizeof(analog->name), "%s %d-hat", - analog->name, hweight16(analog->mask & ANALOG_HATS_ALL)); + seq_buf_printf(&s, " %d-hat", + hweight16(analog->mask & ANALOG_HATS_ALL)); if (analog->mask & ANALOG_HAT_FCS) - strlcat(analog->name, " FCS", sizeof(analog->name)); + seq_buf_printf(&s, " FCS"); if (analog->mask & ANALOG_ANY_CHF) - strlcat(analog->name, (analog->mask & ANALOG_SAITEK) ? " Saitek" : " CHF", - sizeof(analog->name)); + seq_buf_printf(&s, (analog->mask & ANALOG_SAITEK) ? " Saitek" : " CHF"); - strlcat(analog->name, (analog->mask & ANALOG_GAMEPAD) ? " gamepad": " joystick", - sizeof(analog->name)); + seq_buf_printf(&s, (analog->mask & ANALOG_GAMEPAD) ? " gamepad": " joystick"); } /*