From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 250752CA7 for ; Tue, 25 Jan 2022 22:27:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B7F5C340E0; Tue, 25 Jan 2022 22:27:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643149676; bh=21Wcgn1j9relNyi3Uz6u2QsAkpxOeBhxGiQVPqE19R4=; h=Date:From:To:Cc:Subject:From; b=Gj0nd8JJzBg2ACxpoOnKSAcoEBiYNetMzpqhFkBlB8pUui+yl2xZdzXiV5bfg2hAI +5U2cQKH2/DUpwIyfrjcJN1c03InGAJ1p9eHpF0s/Xr0bhM4maFEqYz0jlWHSg03cG VYwqPX9XEImDw0ojzIzhtfsULg80yFT5FVCsneauZoKgyXw2vJDngxmgbSyUJxZL6m iaKD10QhK4Ua9NCiZdZzw4dvh31PsatVTyw3Lre0S9lVL8OB2MHjq+6MqjSG8ra0iq n0k1NuRBz2HY0bJQ3savB8v6LJuRnFOSl8JJMXooLF+2enassriW2Q91Vvx8FtP3nW Q1tLdEbmK/kxw== Date: Tue, 25 Jan 2022 16:34:43 -0600 From: "Gustavo A. R. Silva" To: David Kershner , Greg Kroah-Hartman Cc: sparmaintainer@unisys.com, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] staging: unisys: visorinput: Use struct_size() helper in kzalloc() Message-ID: <20220125223443.GA76937@embeddedor> Precedence: bulk X-Mailing-List: linux-staging@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worst scenario, could lead to heap overflows. Also, address the following sparse warnings: drivers/staging/unisys/visorinput/visorinput.c:409:27: warning: using sizeof on a flexible structure Link: https://github.com/KSPP/linux/issues/174 Signed-off-by: Gustavo A. R. Silva --- drivers/staging/unisys/visorinput/visorinput.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/staging/unisys/visorinput/visorinput.c b/drivers/staging/unisys/visorinput/visorinput.c index 426deab22d62..dffa71ac3cc5 100644 --- a/drivers/staging/unisys/visorinput/visorinput.c +++ b/drivers/staging/unisys/visorinput/visorinput.c @@ -406,7 +406,8 @@ static struct visorinput_devdata *devdata_create(struct visor_device *dev, if (dtype == visorinput_keyboard) /* allocate room for devdata->keycode_table, filled in below */ extra_bytes = KEYCODE_TABLE_BYTES * 2; - devdata = kzalloc(sizeof(*devdata) + extra_bytes, GFP_KERNEL); + devdata = kzalloc(struct_size(devdata, keycode_table, extra_bytes), + GFP_KERNEL); if (!devdata) return NULL; mutex_init(&devdata->lock_visor_dev); -- 2.27.0