From patchwork Sun Sep 24 06:57:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 144057 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp570836vqu; Sun, 24 Sep 2023 02:07:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG8/jkiwMndz8SUerYMhAb/yQxeN9Ldg01ulPGegILgveLpklq//diyQQ7343E6moHA3CCH X-Received: by 2002:a05:6e02:12e5:b0:34f:c9b4:5f9e with SMTP id l5-20020a056e0212e500b0034fc9b45f9emr5758046iln.19.1695546428333; Sun, 24 Sep 2023 02:07:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695546428; cv=none; d=google.com; s=arc-20160816; b=WXGfmjNSoNWFDg//1RO8pdwDhMFCvwFM6JN8rQzV/fGkR5UBLlSTYwbeWQtRmfZ/lz dyjklX7aNGDxQNjvARDM23WS5oPXIf0vxLY3JTjvnuPnBkPLoa8OtG4io3Rc1LaCmqg5 0aVbBnFqHBZ3tkBAj+eMN0gT2HLTs8Yhih856OHyvxNttvM6VUtDwYGIOGrqFHvb2WZc NYpeKHn19HLxWOXV6g8lTlGnVsO15Vy3Gny7fHhpCn7Znih6+eFZ3WxPVcP9OLMsDqkM GtXJGQDwfLDDWemTgtvmEpEAzOVcc3hrQf2v4ljrkeE+5Jm2H7SmMToyI2NFRVZs0lOn FFDw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PSnDJBNGC1tP4164Wnhkgh8HavtiyRUWc4qNKuLAPY0=; fh=F+N3GMBcdtipU+1HtmBUlKjxC7FTWqtH2VQVBAT6f9g=; b=TfpOADp55zCgDaPDfCZaoA083aybwHYX6Mos2UYst6pvEda6Ig33cv9OUpnmQJzWws RELjPEiQOgxM1uX/DMS8+H8qhConidtT70NHf5aH1cyhJQS1rB6G+tJZnHQrRZ2x6L/2 NLM4XGnNRlHODk5BeTymf4lXAdyI+wEMpoJXFi7EFP3ELWrHLNsZ0+vQjRzgwx68j0ot tRKyKK2E7NDa0J1UZPzI5AC4OxeUK+aRqRvVm+PaqpSUMqamDWijUshDuWkKVL9POaH1 1kIBcL4pK1adGj0yLJBTLOTc/3XSH+En9CppdKNtc6zErwVJWjJS1LEmNnZU2PlPsXKD uH4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=HLMnRd41; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id l12-20020a63da4c000000b00565f0e91894si7597491pgj.394.2023.09.24.02.07.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 02:07:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=HLMnRd41; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id E18EB8027664; Sat, 23 Sep 2023 23:58:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229914AbjIXG6F (ORCPT + 30 others); Sun, 24 Sep 2023 02:58:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbjIXG6E (ORCPT ); Sun, 24 Sep 2023 02:58:04 -0400 Received: from smtp.smtpout.orange.fr (smtp-17.smtpout.orange.fr [80.12.242.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7189410D for ; Sat, 23 Sep 2023 23:57:57 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id kJ3wqxINJLxWbkJ3zqOyHM; Sun, 24 Sep 2023 08:57:56 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1695538676; bh=PSnDJBNGC1tP4164Wnhkgh8HavtiyRUWc4qNKuLAPY0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=HLMnRd41/RUlgoc93i1SIhYkHq4NIqC574gjkWB0wtvQ55rvb2zCtXdUMPKd0zAGr a4laNmOjx1eAun7nxTaLBZ678kfZtjMV29BjIoT2jUFKy8m82k22xZ7gQuelOTfDQa 8zwsYXndljlF4XHMVhTjzATM11djyI9GlEXFmTqv9pTdtnEMHBpYn0boBcOIEkh5KZ k4p1NNnKDF8NQzMDYPrFBH3H6qhyyhLccHjViohypu5My4lSTlr0aObzdWbkSJ4RZ0 pDHyfWfsU1vTWFQx4kYZcbysaMC9r2KOWYB9JOZQbL5NLVoADv1Pq7bLPWTPAC9BHO LeTyhIKgQjDRw== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 24 Sep 2023 08:57:56 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Kalle Valo Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-wireless@vger.kernel.org Subject: [PATCH wireless-next 2/2] ath: dfs_pattern_detector: Use flex array to simplify code Date: Sun, 24 Sep 2023 08:57:50 +0200 Message-Id: <1920cc38db2e570633e13b37d50852f3202a7270.1695538105.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sat, 23 Sep 2023 23:58:08 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777909291567995668 X-GMAIL-MSGID: 1777909291567995668 At the time of the writing, the value of 'num_radar_types' is 7 or 9. So on a 64 bits system, only 56 or 72 bytes are allocated for the 'detectors' array. Turn it into a flex array, in order to simplify memory management and save an indirection when the array is used. Doing so, cd->detectors can't be NULL, and channel_detector_exit() can be simplified as well. Signed-off-by: Christophe JAILLET Reviewed-by: Jeff Johnson --- Patch #1/2 is a fix, for for wireless. Patch #2/2 is for wireless-next I guess, but depnds on #1 Not sure if we can mix different target in the same serie. Let me know. --- .../net/wireless/ath/dfs_pattern_detector.c | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/net/wireless/ath/dfs_pattern_detector.c b/drivers/net/wireless/ath/dfs_pattern_detector.c index 2788a1b06c17..700da9f4531e 100644 --- a/drivers/net/wireless/ath/dfs_pattern_detector.c +++ b/drivers/net/wireless/ath/dfs_pattern_detector.c @@ -161,7 +161,7 @@ get_dfs_domain_radar_types(enum nl80211_dfs_regions region) struct channel_detector { struct list_head head; u16 freq; - struct pri_detector **detectors; + struct pri_detector *detectors[]; }; /* channel_detector_reset() - reset detector lines for a given channel */ @@ -183,14 +183,13 @@ static void channel_detector_exit(struct dfs_pattern_detector *dpd, if (cd == NULL) return; list_del(&cd->head); - if (cd->detectors) { - for (i = 0; i < dpd->num_radar_types; i++) { - struct pri_detector *de = cd->detectors[i]; - if (de != NULL) - de->exit(de); - } + + for (i = 0; i < dpd->num_radar_types; i++) { + struct pri_detector *de = cd->detectors[i]; + if (de != NULL) + de->exit(de); } - kfree(cd->detectors); + kfree(cd); } @@ -200,16 +199,12 @@ channel_detector_create(struct dfs_pattern_detector *dpd, u16 freq) u32 i; struct channel_detector *cd; - cd = kmalloc(sizeof(*cd), GFP_ATOMIC); + cd = kzalloc(struct_size(cd, detectors, dpd->num_radar_types), GFP_ATOMIC); if (cd == NULL) goto fail; INIT_LIST_HEAD(&cd->head); cd->freq = freq; - cd->detectors = kcalloc(dpd->num_radar_types, - sizeof(*cd->detectors), GFP_ATOMIC); - if (cd->detectors == NULL) - goto fail; for (i = 0; i < dpd->num_radar_types; i++) { const struct radar_detector_specs *rs = &dpd->radar_spec[i];