From: Heiner Kallweit <hkallweit1@gmail.com>
To: Thangaraj.S@microchip.com, andrew+netdev@lunn.ch,
davem@davemloft.net, Rengarajan.S@microchip.com, kuba@kernel.org,
pabeni@redhat.com, edumazet@google.com,
UNGLinuxDriver@microchip.com
Cc: linux-usb@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH v2 net-next] net: usb: lan78xx: make struct fphy_status static const
Date: Wed, 11 Jun 2025 21:16:37 +0200 [thread overview]
Message-ID: <be4598a3-7880-4efc-a1c7-d5093f4c9eaf@gmail.com> (raw)
In-Reply-To: <58e97a033835bc9347e24ff50aea26275054e9b2.camel@microchip.com>
On 11.06.2025 09:02, Thangaraj.S@microchip.com wrote:
> Hi Heiner,
> Thanks for the patch
> On Tue, 2025-06-10 at 22:58 +0200, Heiner Kallweit wrote:
>> EXTERNAL EMAIL: Do not click links or open attachments unless you
>> know the content is safe
>>
>> Constify variable fphy_status and make it static.
>>
>> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
>> ---
>> v2:
>> - extend commit message
>> ---
>> drivers/net/usb/lan78xx.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c
>> index 759dab980..17c23eada 100644
>> --- a/drivers/net/usb/lan78xx.c
>> +++ b/drivers/net/usb/lan78xx.c
>> @@ -2630,7 +2630,7 @@ static int lan78xx_configure_flowcontrol(struct
>> lan78xx_net *dev,
>> */
>> static struct phy_device *lan78xx_register_fixed_phy(struct
>> lan78xx_net *dev)
>> {
>> - struct fixed_phy_status fphy_status = {
>> + static const struct fixed_phy_status fphy_status = {
>> .link = 1,
>> .speed = SPEED_1000,
>> .duplex = DUPLEX_FULL,
>> --
>> 2.49.0
>>
>
> This patch changes fphy_status to static const, but as far as I can tell,the function is only called once during probe, and the struct is
> initialized and used immediately. Since it's not reused and doesn't
> need to persist beyond the function call, I don't see a clear reason
> for making it static const. Is there a specific motivation behind this
> change?
>
From a compiler perspective there's not much of a difference, also as of today
the compiler uses a pre-filled struct instead of creating it dynamically.
At least that's the case for me with gcc 15.1.1. Just that with the change
the prefilled struct is properly placed in the rodata segment.
Main reason is to make clear to the reader, and to the compiler, that this
is immutable configuration data. Not different from e.g. regmap users, where
typically a static const struct regmap_config is used for initialization.
> Thanks,
> Thangaraj Samynathan
Heiner
next prev parent reply other threads:[~2025-06-11 19:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-10 20:58 [PATCH v2 net-next] net: usb: lan78xx: make struct fphy_status static const Heiner Kallweit
2025-06-11 7:02 ` Thangaraj.S
2025-06-11 19:16 ` Heiner Kallweit [this message]
2025-06-11 21:30 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=be4598a3-7880-4efc-a1c7-d5093f4c9eaf@gmail.com \
--to=hkallweit1@gmail.com \
--cc=Rengarajan.S@microchip.com \
--cc=Thangaraj.S@microchip.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox