Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4237906pxf; Tue, 23 Mar 2021 06:18:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNmaT2ZAzKQwJaPOnMKuAPxGK0k+BA3EqYKh+Trcamn6ZG42tBb0IeO+XlzLkkCmAY+UU2 X-Received: by 2002:a05:6402:2076:: with SMTP id bd22mr4521369edb.378.1616505489171; Tue, 23 Mar 2021 06:18:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616505489; cv=none; d=google.com; s=arc-20160816; b=0C6LI0LxL76CiULglRhw0XQE1OhDi23Z1j4f3k9UbFVnkQxyMFVV6k/MpViZzDxS7g yH93OdBWByYf9XE91bgu/g9wdigxaCuXLTl99bT8ohA+fujXX8y0Ldnm+BwUFyRxBWEF 9rCBpPpNZBqP+h0t5/P34CAyIbzm0XTYLLx4mYudLtdE0QHiGqyyPiyk8Sq5WsNl53W8 ESXVSv+nuU/SRkRbV0QrcZgQvvwI5E4MwWP5s4fKjzgsldGOPBVrQB8MfYLQ59HpMZcU rAJ1I7zBYYc6f0zVQoeHYGPgDhA7C2irDl1JHPR1Ghgbb3JJwL738hPT9OPnCDN2tpqD 9CvA== 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=u81Cv60xYNeAMRCEtIDRscyRHoBGS+qrfIH1ivIizFU=; b=a/nPU/v/d9dUKclwlW9LBkRORLHTdUuDBy2h/NXd3SRxbsQ60tuGo9QosFCtSaM73s vKmJvP3159M/SdEAXVo3P0+VDgDI2/zxbQSkc+vwS6XJ2H/aG0D/DLcSB1z4DqIngoz6 l+KG6FYq+p6ZWi8aWFoAwEROBsXHLmqgbwcnwfCmlb4FnisMgXpD6U5+8jtAek8PcYFI y99Z4SLw6dV4s860mka/JhDpe2H2tnStObQDUB+ciQtl0xmjeiaVG5HkJM8HsxtjAgCT FkuS4zLCzDWOJCYdVq4K072YWvB44q8qzsM6gFgnc1r3n+ma4kcaugcxv0ySvQ9ZFoIv a5nQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gJi5SVgZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 k12si13513060edq.82.2021.03.23.06.17.46; Tue, 23 Mar 2021 06:18:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=gJi5SVgZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 S231687AbhCWNPd (ORCPT + 99 others); Tue, 23 Mar 2021 09:15:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:45294 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231604AbhCWNPC (ORCPT ); Tue, 23 Mar 2021 09:15:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6D31161990; Tue, 23 Mar 2021 13:14:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616505299; bh=oZWMWFmkjgEXpfFZpnhWD7nZruvCO/j1q+o49Q6vXsI=; h=From:To:Cc:Subject:Date:From; b=gJi5SVgZwxCnk/OsOMJBb/xRicHFr1hntHN72DxBJb7F8o3Pqs2ZZ1dD70pQP8caU 9/6AzducHf/9WDhtkWdRgNF6jdmZCPl77JzYmkZF5mnNVmT3KCGQj26ZbsVtx7EixN 5Jdh+ddoxe2vy8Zbi2zb6Ztgs7X5F2ffC4GkjlKbfzbeSe5nonSNCdLO/WUfBA21s2 DSAAXFCQ3UG/5w80ftGe0ecxnN+7X10QOFPzCkhge4Y5mfdb6NIHasbAGfpX3TetnO GP09XUfJbmmEsyQrHxbBLqIIEt2k3MHofwIfUBuqdDfhsAoaBdkd42i/SBDkOL1j9p s9JhcwPmlzOag== From: Arnd Bergmann To: Dmitry Torokhov Cc: Arnd Bergmann , Zhang Qilong , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] Input: analog - fix invalid snprintf() call Date: Tue, 23 Mar 2021 14:14:50 +0100 Message-Id: <20210323131456.2600132-1-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 just use the offset it already knows. Signed-off-by: Arnd Bergmann --- drivers/input/joystick/analog.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/input/joystick/analog.c b/drivers/input/joystick/analog.c index f798922a4598..8c9fed3f13e2 100644 --- a/drivers/input/joystick/analog.c +++ b/drivers/input/joystick/analog.c @@ -419,14 +419,16 @@ 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", + int len; + + len = snprintf(analog->name, sizeof(analog->name), "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)); + len += snprintf(analog->name + len, sizeof(analog->name) - len, "%d-hat", + hweight16(analog->mask & ANALOG_HATS_ALL)); if (analog->mask & ANALOG_HAT_FCS) strlcat(analog->name, " FCS", sizeof(analog->name)); -- 2.29.2