Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp643834rdh; Sun, 24 Sep 2023 06:00:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEEK7T2iBZ2gMaadoBcp3u95zYBULtVSqV8EXKtHB8Al9nDBJoAapVoWk+nwFSVtOiQfCzi X-Received: by 2002:a05:6870:a40f:b0:1bb:51e4:9483 with SMTP id m15-20020a056870a40f00b001bb51e49483mr4037713oal.45.1695560426627; Sun, 24 Sep 2023 06:00:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695560426; cv=none; d=google.com; s=arc-20160816; b=UWik9xFJixhXSGWgkeUXXl0YnmkYluX5IW9rTJYDF0p8ofOY/ptP12ljCayrmHHFqk o6DPa7N7EhHDEPSUe4iU0IELK6o7Av89U1J7g2/CHWXmS9dEQFTbtRs+4Ux47Ayx6seD fgsNl9DrubmJQT8vL+djLasW40wzn86+s/tXG6zK2Jc05CbJeMhsTrKou9rh0IXCKSFd 6eiGZ6XoaHrDCgX7JZYhxmocF5AJOFxiz1QwhLsc/S1sj/K0rdXjcmGFh6ibPgIYzWy5 ICEOn0qXuJhFmzPX+rPsH6oKBPUVgs9h0p45vj0eEboaOXLJUO/9T8VvQYKW9PdldtQp 87/g== 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:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id m1-20020a656a01000000b00578ca21773fsi8396000pgu.718.2023.09.24.06.00.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 06:00:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; 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:8 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 fry.vger.email (Postfix) with ESMTP id 29D1980BB1C0; Sat, 23 Sep 2023 23:58:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229912AbjIXG6F (ORCPT + 99 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email 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 (fry.vger.email [0.0.0.0]); Sat, 23 Sep 2023 23:58:09 -0700 (PDT) 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 --- 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]; -- 2.34.1