From patchwork Mon Aug 19 04:58:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13767900 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 81517C3DA4A for ; Mon, 19 Aug 2024 05:02:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ITu37U4/rpe9ZTz2X5NzcdA46rL5xwCcVFnyhFY3V3s=; b=Q/Q/rzIrI3HUZxDi+W9xWEiKJj QG0jzR+dodqmzBftUV2GWcz4zM79AX9h37rmwtKYtLxZjtP9PysAqOYb/eYDPtP0Kkeqj8noYotsV op5LduTPleT65Sqis9xr8lHXQ73EY3uaVgHQJ4++Osyh31vpBLzUKhwA0g8cp0hLEQXvHRzLxNueA NVvR5CuVsnnzZuv7bGmbmvmxijc6rDrkbhDboQ3HIkNpqBPn+/MrTibl7QibZZxujFRfYHvPQe+nF MkvEAyFwvq/XJa8eDsa5CfN+9kh85CQHW18Khb+lL7eG7ZUmxeJLlxbZtptJHAsahGNYkY8rwB6pt JQYtKNqg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sfuWb-00000000MTJ-47uv; Mon, 19 Aug 2024 05:01:49 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sfuTP-00000000LWv-2eeJ for linux-arm-kernel@lists.infradead.org; Mon, 19 Aug 2024 04:58:32 +0000 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-201f7fb09f6so23877965ad.2 for ; Sun, 18 Aug 2024 21:58:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724043511; x=1724648311; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ITu37U4/rpe9ZTz2X5NzcdA46rL5xwCcVFnyhFY3V3s=; b=AVboSnIa/lPChQ4PCMDDnX9uJA8jBcrXtYfnfdpoMswMtMu0Iko826wY77k6Fq0fro zedu874IufXoXA3MujAi+dCioW+lnfrHsvMUu91j1HLLvJ/OJjhLDFJnJAiMcmPkWf3f LV3Uzb5fl4pbxxDYClLrli1Zpvk8+W0WSgOqnUr4kUaff6cUPlH9Z63he0PnBm8Mj/v7 Bwnv68L1j153O5jgM3g2LTrbcInMKqcbtWdZY+YaPIkdgBR1ZbCca2sLoZNvZjl86j09 V8u6KmOmKBh96s2nRMoUj6LuYyFlX/Mbh86Pt0EzF5HBi+uDGQT6o1tYAylSYX8guPjI n8EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724043511; x=1724648311; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ITu37U4/rpe9ZTz2X5NzcdA46rL5xwCcVFnyhFY3V3s=; b=Be76CSZooSFkpPyxRCEtakq0JinsaZ3H+vevSUCItuUy85zBckbBqF6J56r8R0l5UA lD6qwx/1u3/L17ilh+CFltyIE62sk4g3e22bV50PS58c7yYPJxi8oeAdvnGuetVN/pfO Wi1SPgQRsMmK0JUbaUg7KsdXlA3FVAG7GlJmdlv9xxzIL3zRJxnaoQ3NiL6Zt8AXXVWp KLtoQhq3XCvRp8QIS8ZjrU3jq4hO8pA3XgH5zSvsqnaK41QV7XRH47pkazgFpXVnrJvD E4kbQxiKKezR0zT9wJHh6RXSjSwCvOUpefu9nAdf4F4srbFa4dxN0a26XxP5Dxv989ya Scyg== X-Forwarded-Encrypted: i=1; AJvYcCXvqeAomg3h+9zZ3vasSllOawm2hY7RnHMKFRmwawbzfCHH5UVBkshY8Tzmjz1hrwxtubPqzPOX0srEJpfd5X9N2dro8wOvKxdcAjEb3JxJYS0T6F4= X-Gm-Message-State: AOJu0Ywl7I39VsPQ02iejrzFViyOg6Luoqu9qVyatxety5nKxsJw9nEd vgTsRjkYrjGirIHsQhy33HJ87c6HWoLxNvVTA6vBAL1Lj4WivWZV X-Google-Smtp-Source: AGHT+IGyYm8REzQMteDxukf92aWZeLkKfujBq+Mrydghp3vE1mMv5rcx7DHM0ZE+eHHIzMw7eFWBmw== X-Received: by 2002:a17:903:1d2:b0:202:3107:e769 with SMTP id d9443c01a7336-2023107e9f7mr33840835ad.22.1724043510499; Sun, 18 Aug 2024 21:58:30 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:4eb5:4500:6efc:6c24]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-202068497b4sm43483445ad.269.2024.08.18.21.58.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Aug 2024 21:58:30 -0700 (PDT) From: Dmitry Torokhov To: Arnd Bergmann , Mark Brown , Krzysztof Kozlowski Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, patches@opensource.cirrus.com Subject: [PATCH 04/14] Input: samsung-keypad - use struct_size() helper Date: Sun, 18 Aug 2024 21:58:01 -0700 Message-ID: <20240819045813.2154642-5-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240819045813.2154642-1-dmitry.torokhov@gmail.com> References: <20240819045813.2154642-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240818_215831_688946_4380260C X-CRM114-Status: GOOD ( 13.74 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When allocating memory for the keypad use struct_size() helper to be protected from overflows. Signed-off-by: Dmitry Torokhov Reviewed-by: Krzysztof Kozlowski --- drivers/input/keyboard/samsung-keypad.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/input/keyboard/samsung-keypad.c b/drivers/input/keyboard/samsung-keypad.c index 2be3bfa87ce1..7adcd2657bca 100644 --- a/drivers/input/keyboard/samsung-keypad.c +++ b/drivers/input/keyboard/samsung-keypad.c @@ -318,7 +318,6 @@ static int samsung_keypad_probe(struct platform_device *pdev) struct resource *res; struct input_dev *input_dev; unsigned int row_shift; - unsigned int keymap_size; int error; pdata = dev_get_platdata(&pdev->dev); @@ -345,9 +344,10 @@ static int samsung_keypad_probe(struct platform_device *pdev) pdata->cfg_gpio(pdata->rows, pdata->cols); row_shift = get_count_order(pdata->cols); - keymap_size = (pdata->rows << row_shift) * sizeof(keypad->keycodes[0]); - keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad) + keymap_size, + keypad = devm_kzalloc(&pdev->dev, + struct_size(keypad, keycodes, + pdata->rows << row_shift), GFP_KERNEL); if (!keypad) return -ENOMEM;