From patchwork Sun Jun 2 16:13:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Erick Archer X-Patchwork-Id: 13682963 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2046.outbound.protection.outlook.com [40.92.89.46]) (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 D59004F60D; Sun, 2 Jun 2024 16:13:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.89.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717344817; cv=fail; b=ccEVhk1ZeIBQZkjwj9Eg1uo/TXxJ8x3VefCiGAh6o2vXo6W3/B3TMTdzgUE67r2l7t5Pn9Sc4sI2uKV3+YfTV9+utQ1OrvBynkwcVghR1EXEwE9+Vgu3KHImtbD0GWYO7npNC5oSMECfk1Yp1/dgVsmvRWMZeBewdbTOB8SiyaI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717344817; c=relaxed/simple; bh=Noh6ak1h0VsWbQVl57wwEebajgkSFAVJZESKNvNOG5c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=QJawQQ4LTEeixIyVv+GumG4rIe+E8NazCS4FQrNi+oHoozDECsbA3SRAbSkqtsXoL+qVrpvVnWD0+fkSGDmdxvxIEWQf2sy2o6zb8/VJQqD4NCDXWZQNhtH3AuLvnmsdlJkJKIYK5k0c0a1Ygq7gyXzUn8nxwc93o2JP2KQACsM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com; spf=pass smtp.mailfrom=outlook.com; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b=e5+i6z3q; arc=fail smtp.client-ip=40.92.89.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=outlook.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b="e5+i6z3q" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FZ33S5frt/FZNqhs31GutZReDyjF/zkeR9avH7kB54kJ4LmEblX/suM0PkFsfMpcLfyHvtLmw+CeDQCpnqJ4OO1Yg5azt4PX1h7nlFCs7lek5djIie7h5vC02+WEku1Ou/bM2bXVTX1DwFCc9UwxVY+DOm9HiZHVc4RdUJBXezbuk+em82xE7cNwLl/XsoPP2zyX3XLwjYx8XGoPaH1YXSRCRIkjf2JZ18Cl0xAOS6CelgfjiaHnep1FOmP/Y9ue9YjZ9hp1kWVvmuvvFaMCoQQHwZ9TkCJwSrfdZA80FdINtE5wCsg1rNNRTQz3kyCj5RcFyUAiEFGewRBLUs736g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wVQ3bNPqvr7lI+1aoUFNSPGsO1a466+wjnzIRCJ+ojY=; b=eXjhU8YY67RuLJZZy24hPi4vr8ak2RXn6P2FV54Mh9WGzgFo37aReMxwLX68hJ+ClnXvXjDW+QuvlCu1hkyOYN5+B0uJYDO7qMtCGwuhE8OFuOWFmiAvpg0HTsUk7BYAA4rWRON2jQpcJiuar3KDilxUKDFDg5NGf2YX2c9IAVqI9Wq27Ko0TZtymh9hPriHwDa//sMK28eUO0JI+TyDK6SZo57KftxNd8SgWZv59g443DsHPAnW9kDOvCP4QNHrg4sXCjOEzNA+A6Zax79pjQNZ8BtaDezx5WPKO9jwK/QDyB9JQVGrzDngkGmgmi/zSCoFReTV1JE9KiDHpvxQwA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wVQ3bNPqvr7lI+1aoUFNSPGsO1a466+wjnzIRCJ+ojY=; b=e5+i6z3qJsHYRWgjxSo6rUWhTvAF4/d7FOUA5lGQ/chGIkyP+ispnmKvafmmlLNSMpwwnjOumqIjYgLwmlYX2Kd0owD+V8FuyiXY5qVHLS/yDV+1Ct9j9w5SBgZQQGcs4yv+szwGxaQINoPDdF60UuISOKyuMXMMX6s8O+nQXrpWuYbFbMhOSzNr6MoMJVqnsZbzKtrW+vxoG+0ZcqRwX4h/MKYDTkBncP8faKf06LeEjWikSV1p1h+4n5Ihvbc3nWMQwfHvXiMHRXp8c/gNy8Zqjh8nwPY8rc2tGw9SlefS441DueBCaXUmh+iqw/nxAXAlZp+YTondjZSiISR5iQ== Received: from AS8PR02MB7237.eurprd02.prod.outlook.com (2603:10a6:20b:3f1::10) by DB8PR02MB5770.eurprd02.prod.outlook.com (2603:10a6:10:fa::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.23; Sun, 2 Jun 2024 16:13:32 +0000 Received: from AS8PR02MB7237.eurprd02.prod.outlook.com ([fe80::409b:1407:979b:f658]) by AS8PR02MB7237.eurprd02.prod.outlook.com ([fe80::409b:1407:979b:f658%5]) with mapi id 15.20.7633.021; Sun, 2 Jun 2024 16:13:32 +0000 From: Erick Archer To: Kalle Valo , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Kees Cook , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Greg Kroah-Hartman , Johannes Berg , Alan Stern Cc: Erick Archer , linux-wireless@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH 1/2] atmel: at76c50x: use sizeof(*pointer) instead of sizeof(type) Date: Sun, 2 Jun 2024 18:13:09 +0200 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240602161310.5671-1-erick.archer@outlook.com> References: <20240602161310.5671-1-erick.archer@outlook.com> X-TMN: [MR30IX40Q1PMBu4B6bBJuLNY9GXys/Nr] X-ClientProxiedBy: MA4P292CA0012.ESPP292.PROD.OUTLOOK.COM (2603:10a6:250:2d::9) To AS8PR02MB7237.eurprd02.prod.outlook.com (2603:10a6:20b:3f1::10) X-Microsoft-Original-Message-ID: <20240602161310.5671-2-erick.archer@outlook.com> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR02MB7237:EE_|DB8PR02MB5770:EE_ X-MS-Office365-Filtering-Correlation-Id: 1e412873-8917-4825-c272-08dc831ef295 X-MS-Exchange-SLBlob-MailProps: znQPCv1HvwWBFFzn80jCJQAJVwNE0XiCoJsq6VbH6lRneqLXEuovHqmPRGwooEqhrx9eKosk01UGowsgMAZMEzuHQ9Xt19u99vEFe37xJuybd6nQIM0m695U6/nZzVWsNOsX4h2BX1hTa4l8eVDHFWH/zYMQFVkAn7Szx6dgHrMK36IMbt7x1GWJ5eK+Np/B/n4vssnYyY8Ib7eu780KskCWZVVO1pNDc9TI3tRlnrgNdVXyTXXXIfRyRycyx9VvDDtY+8HyokbmavzZNwDEK38AkiTRCgX4ff+h00A7RDr4yJREOxssKbtotNwUXxOif5X/42jWa/HkJaLjZkEIczmy26fQ1QKAwQ39/RH3JFqtKVmHtk0ENEVoUbeGDpPvVxwPPZsNbbPFGnt3hLA0XmmhLEPOZrRk8X3eedbiC6PuWVtwCPx1hU32PZGsYF2A4IHW/wYERv5x7sjs7v8FYGqnQNyjmHIDVGSNxRJxS4jB6tPJK3FyBHrBh0lJgF6ysTMvP3pKHGIH/Rf8HJFEpnmiMTk+32Bgpgb/Th9nEINFwNQzNJix4UXoStqxXOpx4JVJXVjtYMFb4OVsCaYoiBUaZ5WEyIya7hXQI0m2Z90ig25AXjX7LuUixcvIn/+6bDqdaIkWZ67uceyE215/4g2lsv8m8vMH8POlcNaHlBDs+buZLFP8HeAOLt2DKAWnEYSHLFVxZCDESImrpnfbLzA0SIFUg6dw9C3vppK6skCj1P1bg8u03u8dTXEmspS+HF7pMVRFCYw= X-Microsoft-Antispam: BCL:0;ARA:14566002|461199019|3412199016|440099019|1710799017; X-Microsoft-Antispam-Message-Info: XPCiMnfiuXDcBxTGoDKICA+uFQrqxjiflNOuOpdYSSilfEKVfhdozRuOF64h4u8+1GI5IryVXcVmUaUhPAae8uEyuGdRXDdfQT2B4Fcf69KwFxLUSjYr1s55EXyE+gPBkoQIaN/lLy46rXLVAp7uJQRBDs4W1H4u944/jkmzBzX23ii3fKLr1XrW3j99RDumHYimlFLxNyJtHfhv6qMLAl+BC4gElQfUulkyWzha768pdBbupniBb2/JduPIz8yUEt+Y2GVf+iWGSyFAgxdd0QE3PSBK07lAzxpmhA22IZLYD5QXTv4wm4HSRynEHFlBFyt5Wd9W3DqwvUS2XFBH8BTFapm8TPO7unSulHnEt+7Y28hHRJNV8VVia+7/yYezgm5dEsCl2Bz68JQPfGDEhdSMOMMunoTUPMH2U5kl0t1rTjFfWfZVgpVteUy/Dby58C83frEOQXkaVpiDpk7LtGIqJa6zbDwggGmFD5t33r7dbhmKT7ap2zFQLfF8pF3UtbH4KgiKeet1dWrVEmDUge4L/KFv8fsWdFr5lH/kLiKIHGW6BacPvCGWKQepWp4O7GuBbytinIGfNmDmHwQrZXt3UxG8ioi35/BM5CgPOttex7uJaGSzCHB2VikdbpAb X-MS-Ex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W+eL8MpdXrI1jdJJHV1fpryJbzxvvDhPKNrcvGuIxZdu6P5oV1p/VUDyvsyr9s+zfyv4TklSNGLZ3VTcVRZGat4lDkhB1NFCzGjR0HaqC2zW4jhibQVuqc46tbMMytIqJSmeqL4I9LjOU7v/nwGOyuJZcw3jcxKXSi3eFXHPmXvQ3GquQ7hu21OA0B6Yk0f43m7g5Lh/cpkLZT3LmvhwD+exb2nYgZiKahheEjB6qLdsA/CTCCgFOB X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1e412873-8917-4825-c272-08dc831ef295 X-MS-Exchange-CrossTenant-AuthSource: AS8PR02MB7237.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2024 16:13:32.3787 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR02MB5770 It is preferred to use sizeof(*pointer) instead of sizeof(type) due to the type of the variable can change and one needs not change the former (unlike the latter). This patch has no effect on runtime behavior. At the same time remove some redundant NULL initializations. Signed-off-by: Erick Archer --- drivers/net/wireless/atmel/at76c50x-usb.c | 44 ++++++++++------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/drivers/net/wireless/atmel/at76c50x-usb.c b/drivers/net/wireless/atmel/at76c50x-usb.c index 0b55a272bfd6..0ca2f629683d 100644 --- a/drivers/net/wireless/atmel/at76c50x-usb.c +++ b/drivers/net/wireless/atmel/at76c50x-usb.c @@ -332,7 +332,7 @@ static int at76_dfu_get_status(struct usb_device *udev, ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), DFU_GETSTATUS, USB_TYPE_CLASS | USB_DIR_IN | USB_RECIP_INTERFACE, - 0, 0, status, sizeof(struct dfu_status), + 0, 0, status, sizeof(*status), USB_CTRL_GET_TIMEOUT); return ret; } @@ -366,7 +366,7 @@ static int at76_usbdfu_download(struct usb_device *udev, u8 *buf, u32 size, u32 dfu_timeout = 0; int bsize = 0; int blockno = 0; - struct dfu_status *dfu_stat_buf = NULL; + struct dfu_status *dfu_stat_buf; u8 *dfu_state = NULL; u8 *block = NULL; @@ -378,7 +378,7 @@ static int at76_usbdfu_download(struct usb_device *udev, u8 *buf, u32 size, return -EINVAL; } - dfu_stat_buf = kmalloc(sizeof(struct dfu_status), GFP_KERNEL); + dfu_stat_buf = kmalloc(sizeof(*dfu_stat_buf), GFP_KERNEL); if (!dfu_stat_buf) { ret = -ENOMEM; goto exit; @@ -931,14 +931,12 @@ static void at76_dump_mib_mac_addr(struct at76_priv *priv) { int i; int ret; - struct mib_mac_addr *m = kmalloc(sizeof(struct mib_mac_addr), - GFP_KERNEL); + struct mib_mac_addr *m = kmalloc(sizeof(*m), GFP_KERNEL); if (!m) return; - ret = at76_get_mib(priv->udev, MIB_MAC_ADDR, m, - sizeof(struct mib_mac_addr)); + ret = at76_get_mib(priv->udev, MIB_MAC_ADDR, m, sizeof(*m)); if (ret < 0) { wiphy_err(priv->hw->wiphy, "at76_get_mib (MAC_ADDR) failed: %d\n", ret); @@ -961,13 +959,12 @@ static void at76_dump_mib_mac_wep(struct at76_priv *priv) int i; int ret; int key_len; - struct mib_mac_wep *m = kmalloc(sizeof(struct mib_mac_wep), GFP_KERNEL); + struct mib_mac_wep *m = kmalloc(sizeof(*m), GFP_KERNEL); if (!m) return; - ret = at76_get_mib(priv->udev, MIB_MAC_WEP, m, - sizeof(struct mib_mac_wep)); + ret = at76_get_mib(priv->udev, MIB_MAC_WEP, m, sizeof(*m)); if (ret < 0) { wiphy_err(priv->hw->wiphy, "at76_get_mib (MAC_WEP) failed: %d\n", ret); @@ -997,14 +994,12 @@ static void at76_dump_mib_mac_wep(struct at76_priv *priv) static void at76_dump_mib_mac_mgmt(struct at76_priv *priv) { int ret; - struct mib_mac_mgmt *m = kmalloc(sizeof(struct mib_mac_mgmt), - GFP_KERNEL); + struct mib_mac_mgmt *m = kmalloc(sizeof(*m), GFP_KERNEL); if (!m) return; - ret = at76_get_mib(priv->udev, MIB_MAC_MGMT, m, - sizeof(struct mib_mac_mgmt)); + ret = at76_get_mib(priv->udev, MIB_MAC_MGMT, m, sizeof(*m)); if (ret < 0) { wiphy_err(priv->hw->wiphy, "at76_get_mib (MAC_MGMT) failed: %d\n", ret); @@ -1035,12 +1030,12 @@ static void at76_dump_mib_mac_mgmt(struct at76_priv *priv) static void at76_dump_mib_mac(struct at76_priv *priv) { int ret; - struct mib_mac *m = kmalloc(sizeof(struct mib_mac), GFP_KERNEL); + struct mib_mac *m = kmalloc(sizeof(*m), GFP_KERNEL); if (!m) return; - ret = at76_get_mib(priv->udev, MIB_MAC, m, sizeof(struct mib_mac)); + ret = at76_get_mib(priv->udev, MIB_MAC, m, sizeof(*m)); if (ret < 0) { wiphy_err(priv->hw->wiphy, "at76_get_mib (MAC) failed: %d\n", ret); @@ -1072,12 +1067,12 @@ static void at76_dump_mib_mac(struct at76_priv *priv) static void at76_dump_mib_phy(struct at76_priv *priv) { int ret; - struct mib_phy *m = kmalloc(sizeof(struct mib_phy), GFP_KERNEL); + struct mib_phy *m = kmalloc(sizeof(*m), GFP_KERNEL); if (!m) return; - ret = at76_get_mib(priv->udev, MIB_PHY, m, sizeof(struct mib_phy)); + ret = at76_get_mib(priv->udev, MIB_PHY, m, sizeof(*m)); if (ret < 0) { wiphy_err(priv->hw->wiphy, "at76_get_mib (PHY) failed: %d\n", ret); @@ -1130,13 +1125,12 @@ static void at76_dump_mib_local(struct at76_priv *priv) static void at76_dump_mib_mdomain(struct at76_priv *priv) { int ret; - struct mib_mdomain *m = kmalloc(sizeof(struct mib_mdomain), GFP_KERNEL); + struct mib_mdomain *m = kmalloc(sizeof(*m), GFP_KERNEL); if (!m) return; - ret = at76_get_mib(priv->udev, MIB_MDOMAIN, m, - sizeof(struct mib_mdomain)); + ret = at76_get_mib(priv->udev, MIB_MDOMAIN, m, sizeof(*m)); if (ret < 0) { wiphy_err(priv->hw->wiphy, "at76_get_mib (MDOMAIN) failed: %d\n", ret); @@ -1375,7 +1369,7 @@ static int at76_startup_device(struct at76_priv *priv) priv->scan_min_time, priv->scan_max_time, priv->scan_mode == SCAN_TYPE_ACTIVE ? "active" : "passive"); - memset(ccfg, 0, sizeof(struct at76_card_config)); + memset(ccfg, 0, sizeof(*ccfg)); ccfg->promiscuous_mode = 0; ccfg->short_retry_limit = priv->short_retry_limit; @@ -1411,7 +1405,7 @@ static int at76_startup_device(struct at76_priv *priv) ccfg->beacon_period = cpu_to_le16(priv->beacon_period); ret = at76_set_card_command(priv->udev, CMD_STARTUP, &priv->card_config, - sizeof(struct at76_card_config)); + sizeof(*ccfg)); if (ret < 0) { wiphy_err(priv->hw->wiphy, "at76_set_card_command failed: %d\n", ret); @@ -2443,7 +2437,7 @@ static int at76_probe(struct usb_interface *interface, struct usb_device *udev; int op_mode; int need_ext_fw = 0; - struct mib_fw_version *fwv = NULL; + struct mib_fw_version *fwv; int board_type = (int)id->driver_info; udev = usb_get_dev(interface_to_usbdev(interface)); @@ -2531,7 +2525,7 @@ static int at76_probe(struct usb_interface *interface, usb_set_intfdata(interface, priv); - memcpy(&priv->fw_version, fwv, sizeof(struct mib_fw_version)); + memcpy(&priv->fw_version, fwv, sizeof(*fwv)); priv->board_type = board_type; ret = at76_init_new_device(priv, interface); From patchwork Sun Jun 2 16:13:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Erick Archer X-Patchwork-Id: 13682964 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2046.outbound.protection.outlook.com [40.92.89.46]) (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 DB0B655880; Sun, 2 Jun 2024 16:13:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.89.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717344819; cv=fail; b=kLfVbzRqNmZqxNRt/JZwqT2Jy4KcOz/okHd44VSDCfO0nHVe7nNsOAP8o0rY2OT3AgN0PVsqYttakctODxhdFKFQMueGMCWDDT0vP/Q4q5VRH64MmeK7VieFhuMQhtrnus6erzJ/cjwKAT4FWEYvJsSQXONQuiBW7NYyHA5tmls= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717344819; c=relaxed/simple; bh=HHZCt45ENCwr9fYYe36gugYY2fQ1DPE4hVUi3TgjYK4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=dGDAJSX2oouQ7R/3szxqM5cxpgvwHqoNWzqHgq0tKki/ZkHmgNmE1JB5PblVcpQpEV85FIJxe0f5BpgDjNRyNJG5HJ7Oevp6ugHBvo4qs2xifqIc2PMRmKCp58vXatDgk9OYi+kxgoLOjWc/3r7lP2GXICaMNDpgvGIg/otNxTc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com; spf=pass smtp.mailfrom=outlook.com; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b=nYuMas1x; arc=fail smtp.client-ip=40.92.89.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=outlook.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b="nYuMas1x" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jO0A2ecqAska8cdX4JlP4VyXHZoiyPx9EZu6eaNdKxPsYSwTeSmTxHia83bWeAomhU8hn3avzf+sdv4ZP8mAv4FFqEyKYZKSi5zx5uzgZ+jNKdObi+m7wTS/BJ0Rng5lOhq1TQLqGELbUPsd+tx3ZZJwrmAuYWa9yL+c1j7KnhwrsJk6V1e7CcMf5/7bJUCADdqnjM7LTHS6Abvp0au+rXFL8shDYg6ZRzB3jTL1k8ixm/VMg7CpYClchLtA35jebQhud8q8vZU6+Ox3LFoOEe94ChpNAihVQZHRoe0F6TG+CnTeNNocGdt+JWGZzEbJf02MCRqTPQEtpw+0ZmCCKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4vk8RDDC0FHtje+A9aH90LofaW1j2JUfFYGmT0aycZg=; b=GeMfO5Q9DdlLltcfjNdHuLIaWKxRi/St6YnGLheFhPtbTP+DkCjZgFHNzPBrRWh5TPIpO7YD82wmR0HtoBVXDJVQZaHaG6esC6eeuNuW9iL74SHltK+z8Zh4CRkdGE25K2ZaCbTZxn00CtP0zl+pRBvcuc0zz1QHnTfrVDLRgN7DaX6vCjHW7HxvA8q4b+tzW2gib/rEB6tIC47FQjlyeukszM6nLkikKWXHYXbwhWd/RcwhtNkPPY6QbPEkx+kpX/hBaxs97r3KvFT4TnFlzJpACEWX6Dl2F2fqiHXVnAi1pP92QllTuDlSx9xqg7ldxIB4cfNU9frfwVc8ynyuFg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4vk8RDDC0FHtje+A9aH90LofaW1j2JUfFYGmT0aycZg=; b=nYuMas1xin2RT/3tAkrkUl405xWPoNZlOdmdxSRR/0ZUwO8NuKURcAPFL/8KU9eW7Jc4Q/VcBXwp5ATTUIt3xuUippM+/eWVMMSJ9BHY6rB53MkizSvsSJd6MrINnvKZP5FkR21BOEA8E3FA+FtzFh+KN/nCDkNRgUZSgqoiponZsPIDTmSvhDjSkZ/0olP5gW8J4kUdV3CwdKPI0Akg1B5WJ0kwpuW77dC9NVXNdMvFp+gh3kF6Eeys+EeOaqAfC/NRtMe++asD1IwLESJblt3I+drMneEjebOmz9sWsc9iStlfPdTf/i+OvOn8OFKLfUM6WNohcf65EkhtusXmgg== Received: from AS8PR02MB7237.eurprd02.prod.outlook.com (2603:10a6:20b:3f1::10) by DB8PR02MB5770.eurprd02.prod.outlook.com (2603:10a6:10:fa::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.23; Sun, 2 Jun 2024 16:13:33 +0000 Received: from AS8PR02MB7237.eurprd02.prod.outlook.com ([fe80::409b:1407:979b:f658]) by AS8PR02MB7237.eurprd02.prod.outlook.com ([fe80::409b:1407:979b:f658%5]) with mapi id 15.20.7633.021; Sun, 2 Jun 2024 16:13:33 +0000 From: Erick Archer To: Kalle Valo , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Kees Cook , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Greg Kroah-Hartman , Johannes Berg , Alan Stern Cc: Erick Archer , linux-wireless@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH 2/2] atmel: at76c50x: prefer struct_size over open coded arithmetic Date: Sun, 2 Jun 2024 18:13:10 +0200 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240602161310.5671-1-erick.archer@outlook.com> References: <20240602161310.5671-1-erick.archer@outlook.com> X-TMN: [az89DfLxJTvwGPqRyiYJ1EJORx8gvOjr] X-ClientProxiedBy: MA4P292CA0012.ESPP292.PROD.OUTLOOK.COM (2603:10a6:250:2d::9) To AS8PR02MB7237.eurprd02.prod.outlook.com (2603:10a6:20b:3f1::10) X-Microsoft-Original-Message-ID: <20240602161310.5671-3-erick.archer@outlook.com> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR02MB7237:EE_|DB8PR02MB5770:EE_ X-MS-Office365-Filtering-Correlation-Id: ac614939-b2e4-49f9-ab1f-08dc831ef33e X-MS-Exchange-SLBlob-MailProps: Z68gl6A5j2/PepXNWlrNMoNaS1G7uLgXpcUMo4vWkBnT142L0PGTXeKYSl2h2kpkHbSHtqxqcjJ+ygmQCrpfZJXNVl5lDAUB4k98ENfTJ/gIstTV0psUTuVEJ67urii9zQbWKujWOYF/8HknEbhfFUhAFHrQmSM0ZzgMlGbZZoOjX3/syDeqGDmna/v3tOLXoVN8Elo7UIoI/TBtNysgdostAf+sTgdhuop29z3KJ2xDqVHuH4i2QCe1S8NB7IQEYCJnP+7eGmfRN9YYNAraZZiSSdy2Jhz2TI8p6sXRmpGS1zHh9NSpwWRwJzLiV+KtkNAogIdvaKiE8rHnwwSY96QaABhTwR1P72bgHOTb2ytOS1EV8lIvjO6h+8CJ6sImTTwaXundjGoPeDJnixQwFvX6y4EI/XPvM/dlI5tlqR5uTrgtWrpBv1clf6Zgs5J1AqS9GEPZI/di/SWAAEfNqbZbazMI5QWmX+RgYa77thRx/9+JiJzJF8juyJIByGO+UHEA7gm9CfrkMpBJy8pa5cWMSPFDYHj5nrmy6LITPalPQ26TziWRtzGR0HaBYfjOa7oEkxFwjbcPSfHSMq7Py6mfVCkhLyX5UEfGBD6PyHMzea9nCLw/anZDnkDDxDAA/rG+AFOAlE5LjQ7F6T19wGKxH2/jVQRx7AW52L5W8RR+AIfBPwwIXo6xX15qS8o9pO32LJuZxP6/r5oCBEdOb98Y5+Ksuj0gJtvWxKLM+co1s4qeOnoy2Lxpg/3Bw7pDLanBOiz/R0whnvbf4EaCPq6asOctHgFFXzSJCKP6TArwkKBLfbIzv8Fmo4QlnHWJ X-Microsoft-Antispam: BCL:0;ARA:14566002|461199019|1602099003|3412199016|440099019|1710799017; X-Microsoft-Antispam-Message-Info: 1M6q4aqO2MFIUPqu2/6AX7+TLKh0mTyK7WKUkueoQcIENi7ovWB31Kf8K8tzi11UBCWySJygH/MUuWVl+WbE8AyCPs7NpKEh/kpdxhKN32w2DCube2I/3GN70BlAQls0Ux5xidOKKVSRum2qCxzVYPjOdTCoxFgJjzznfWjZIfKRVRv3oAMjesMURzDjmzeBnLqcrqz5544LbSngHTa6Sw2m9RTVivy1K30kG8jelX3UwQ7EgVbBdOhIGIkOhEsMstGYxMVbghe2p8HLEHXcTiQst1E9xf1QzshfSulPt8uAxkpZKC9HluFwQVzprii9n58HaGgMEgVruuVDmpJPt9plgrPKMee+VpZQ6ivV2siHb+9HaW6tvi38O3BM08BCjyTEUKG4nWxdQKrqrIzz9C4rnrMiuvYCOGx7NrRF5w84AHeANcTn2mPqTtoGi/U2M6HKbQ9p2L3iWU9NNuSauCu4EyWR/4NkkgUA7JUOTVHz0Fbv2yuRwpOAKaSxV3FhnyUy2cR1ZtZm0RAvYo3dGONeoUlT5HbhK45Vqf7g6sbcKkbC3+C1cQiBL5wzKbCQryh53He89wppSSxmrWUS8FdwHu388Onpq3dXkgegskZK+QA3HOrN0LrvUpafDa2ooQQhWuvEgGMCHPBv5i3qQ5HBlaYjKFlmhdOT6bUONI/788R1isp7+5br0GMsFmTcGigJImtU8JOhd14wGmgZVg== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6ovNg1n+1SOBlpKczqP0m63dSR1454YdTzqfSuIpg++asG1X8/TWvZEE312clmjdQYSsrit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HGIOv8lSLHhVou7ofHouZ+W1WATttR8n4u2E1F9CHWaz9oqw7SfDirjUbXj0O+4KNum+AL6s4cyH96oT1GhMNWoTjrPNrbYUE2Qm03l02EciXuMtGmq+q6JbMVdDjIJrS5Em/0hbPv X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: ac614939-b2e4-49f9-ab1f-08dc831ef33e X-MS-Exchange-CrossTenant-AuthSource: AS8PR02MB7237.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2024 16:13:33.4568 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR02MB5770 This is an effort to get rid of all multiplications from allocation functions in order to prevent integer overflows [1][2]. As the "cmd_buf" variable is a pointer to "struct at76_command" and this structure ends in a flexible array: struct at76_command { [...] u8 data[]; } __packed; the preferred way in the kernel is to use the struct_size() helper to do the arithmetic instead of the calculation "size + count" in the kmalloc() function. Also, declare a new variable (total_size) since the return value of the struct_size() helper is used several times. At the same time, prepare for the coming implementation by GCC and Clang of the __counted_by attribute. Flexible array members annotated with __counted_by can have their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions). In this case, it is important to note that the attribute used is "__counted_by_le" since the counter type is "__le16". This way, the code is more readable and safer. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments [1] Link: https://github.com/KSPP/linux/issues/160 [2] Signed-off-by: Erick Archer --- drivers/net/wireless/atmel/at76c50x-usb.c | 12 ++++++------ drivers/net/wireless/atmel/at76c50x-usb.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/atmel/at76c50x-usb.c b/drivers/net/wireless/atmel/at76c50x-usb.c index 0ca2f629683d..baa53cfefe48 100644 --- a/drivers/net/wireless/atmel/at76c50x-usb.c +++ b/drivers/net/wireless/atmel/at76c50x-usb.c @@ -721,9 +721,11 @@ static int at76_set_card_command(struct usb_device *udev, u8 cmd, void *buf, int buf_size) { int ret; - struct at76_command *cmd_buf = kmalloc(sizeof(struct at76_command) + - buf_size, GFP_KERNEL); + size_t total_size; + struct at76_command *cmd_buf; + total_size = struct_size(cmd_buf, data, buf_size); + cmd_buf = kmalloc(total_size, GFP_KERNEL); if (!cmd_buf) return -ENOMEM; @@ -732,15 +734,13 @@ static int at76_set_card_command(struct usb_device *udev, u8 cmd, void *buf, cmd_buf->size = cpu_to_le16(buf_size); memcpy(cmd_buf->data, buf, buf_size); - at76_dbg_dump(DBG_CMD, cmd_buf, sizeof(struct at76_command) + buf_size, + at76_dbg_dump(DBG_CMD, cmd_buf, total_size, "issuing command %s (0x%02x)", at76_get_cmd_string(cmd), cmd); ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x0e, USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE, - 0, 0, cmd_buf, - sizeof(struct at76_command) + buf_size, - USB_CTRL_GET_TIMEOUT); + 0, 0, cmd_buf, total_size, USB_CTRL_GET_TIMEOUT); kfree(cmd_buf); return ret; } diff --git a/drivers/net/wireless/atmel/at76c50x-usb.h b/drivers/net/wireless/atmel/at76c50x-usb.h index 746e64dfd8aa..843146a0de64 100644 --- a/drivers/net/wireless/atmel/at76c50x-usb.h +++ b/drivers/net/wireless/atmel/at76c50x-usb.h @@ -151,7 +151,7 @@ struct at76_command { u8 cmd; u8 reserved; __le16 size; - u8 data[]; + u8 data[] __counted_by_le(size); } __packed; /* Length of Atmel-specific Rx header before 802.11 frame */