From patchwork Sun Nov 20 09:34:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 23399 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1045684wrr; Sun, 20 Nov 2022 01:39:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf7zBJTTasKG1NHnMoopa6RmuYJDo6WCY+4VWy7nhASmCluywQDOrTxFQBYY1sY3Zb+rzC0T X-Received: by 2002:a05:6402:1855:b0:45c:fca7:e094 with SMTP id v21-20020a056402185500b0045cfca7e094mr11825728edy.314.1668937141023; Sun, 20 Nov 2022 01:39:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668937141; cv=none; d=google.com; s=arc-20160816; b=fqPW5mrS4A8GMsBnk42cmh8wGCYdLhsuRLBLY2xwl/WlppozsW6fdtB9X/1tAuG31d FS1OOV2WONXmHCpx1dSclF0NsQ8vjVJ1EO4kiK3cwNOd9KOA6nDyvTdvja+DyDMARWSg B8ZG/gGDNBBn37h1268kRIwkUW94yrZxZpLboNIsPbhF17ycrUX3EucJryqTyBqyhfCr b9pkwZCVlPIwoYtajo5l+VJ5j7Q2c/wjRT1Yn8A6nNMTC6cdwUUezzvUvipmTk/yzwJS BJpq5brKHZZQJFE/249EAO+2skFkzCgZoFgDeWYiZGgXYALo/PevhR0Pr3Nd/4/K//TX ocrA== 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 :message-id:date:subject:cc:to:from; bh=+9akxyOFYlh6V+fgETloIc812H8USf/ihKB5+QoXq4Y=; b=uxGsju2tmIk3TU6DpbpVAXIh53Kh8/aW4leAghxPbC3+gfhmyc5RslrmWuoqpjXjlw D9+ry4bP42cLUHwwV3M69hzFe5g7PLAk2XGfh6NPAA3VZL8Mjv0VBU8VV5t1NvZPX2Hg HRyMqLiT6xl523I+jsbf9SbRa04jYvHhfqb6DSKxmXxDdWh5KTR9ikpZYVbJyAJV6zD4 RnyN4o2BDnp9qAGjRBr04TDF7n8orFfCNqiwBXMJnSbDGZ2fj3BmiGV9eBBMl1RuzfIQ jJLmcZkaldIlVurnFco+HD3pk8NFa+3UZPzLOOZJrm0Ou00Dm9zqv5alqIRcNvw95U9s Uvcg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xh13-20020a170906da8d00b0078e29796733si1789122ejb.653.2022.11.20.01.38.37; Sun, 20 Nov 2022 01:39:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229524AbiKTJeu (ORCPT + 99 others); Sun, 20 Nov 2022 04:34:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229500AbiKTJer (ORCPT ); Sun, 20 Nov 2022 04:34:47 -0500 Received: from smtp.smtpout.orange.fr (smtp-16.smtpout.orange.fr [80.12.242.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEE9F1CFFE for ; Sun, 20 Nov 2022 01:34:45 -0800 (PST) Received: from pop-os.home ([86.243.100.34]) by smtp.orange.fr with ESMTPA id wgiooJbLW0H6IwgioonYC1; Sun, 20 Nov 2022 10:34:44 +0100 X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 20 Nov 2022 10:34:44 +0100 X-ME-IP: 86.243.100.34 From: Christophe JAILLET To: Tim Harvey , Jean Delvare , Guenter Roeck Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-hwmon@vger.kernel.org Subject: [PATCH] hwmon: (gsc-hwmon) Switch to flexible array to simplify code Date: Sun, 20 Nov 2022 10:34:41 +0100 Message-Id: <61a23e1d642397cfcecc4ac3bb0ab485d257987d.1668936855.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750007431700918558?= X-GMAIL-MSGID: =?utf-8?q?1750007431700918558?= Using flexible array is more straight forward. It - saves 1 pointer in the 'gsc_hwmon_platform_data' structure - saves an indirection when using this array - saves some LoC and avoids some always spurious pointer arithmetic Signed-off-by: Christophe JAILLET --- Compile tested only --- drivers/hwmon/gsc-hwmon.c | 6 ++---- include/linux/platform_data/gsc_hwmon.h | 5 ++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/hwmon/gsc-hwmon.c b/drivers/hwmon/gsc-hwmon.c index b60ec95b5edb..73e5d92b200b 100644 --- a/drivers/hwmon/gsc-hwmon.c +++ b/drivers/hwmon/gsc-hwmon.c @@ -257,13 +257,10 @@ gsc_hwmon_get_devtree_pdata(struct device *dev) if (nchannels == 0) return ERR_PTR(-ENODEV); - pdata = devm_kzalloc(dev, - sizeof(*pdata) + nchannels * sizeof(*ch), + pdata = devm_kzalloc(dev, struct_size(pdata, channels, nchannels), GFP_KERNEL); if (!pdata) return ERR_PTR(-ENOMEM); - ch = (struct gsc_hwmon_channel *)(pdata + 1); - pdata->channels = ch; pdata->nchannels = nchannels; /* fan controller base address */ @@ -277,6 +274,7 @@ gsc_hwmon_get_devtree_pdata(struct device *dev) of_node_put(fan); + ch = pdata->channels; /* allocate structures for channels and count instances of each type */ device_for_each_child_node(dev, child) { if (fwnode_property_read_string(child, "label", &ch->name)) { diff --git a/include/linux/platform_data/gsc_hwmon.h b/include/linux/platform_data/gsc_hwmon.h index 281f499eda97..f2781aa7eff8 100644 --- a/include/linux/platform_data/gsc_hwmon.h +++ b/include/linux/platform_data/gsc_hwmon.h @@ -29,18 +29,17 @@ struct gsc_hwmon_channel { /** * struct gsc_hwmon_platform_data - platform data for gsc_hwmon driver - * @channels: pointer to array of gsc_hwmon_channel structures - * describing channels * @nchannels: number of elements in @channels array * @vreference: voltage reference (mV) * @resolution: ADC bit resolution * @fan_base: register base for FAN controller + * @channels: array of gsc_hwmon_channel structures describing channels */ struct gsc_hwmon_platform_data { - const struct gsc_hwmon_channel *channels; int nchannels; unsigned int resolution; unsigned int vreference; unsigned int fan_base; + struct gsc_hwmon_channel channels[]; }; #endif