netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Heiner Kallweit <hkallweit1@gmail.com>
Cc: Marek Vasut <marex@denx.de>,
	netdev@vger.kernel.org, Florian Fainelli <f.fainelli@gmail.com>
Subject: Re: [PATCH V3] net: phy: tja11xx: Add TJA11xx PHY driver
Date: Sun, 23 Dec 2018 10:59:40 +0100	[thread overview]
Message-ID: <20181223095940.GA31681@lunn.ch> (raw)
In-Reply-To: <6f19cf67-aef8-9b9c-1993-bf986bb8d41f@gmail.com>

> >>> +	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> >>> +	if (!priv)
> >>> +		return -ENOMEM;
> >>> +
> >>> +	priv->hwmon_name = devm_kstrdup(dev, dev_name(dev), GFP_KERNEL);
> >>> +	if (!priv->hwmon_name)
> >>> +		return -ENODEV;
> >>
> >> Do you really need to make a copy of the device name?
> >> Why not simply priv->hwmon_name = dev_name(dev) ?
> > 
> > Fine by me, but then maybe I don't quite understand why the other
> > drivers duplicate the name, eg. the sfp.c one.
> > 
> It's a question of object lifetime. If the original object can go away
> before your object, then you need to make a copy of the name.
> However in our case I don't think priv can live longer than dev.
> 
> >> And if devm_kstrdup fails, then most likely you have an out-of-memory
> >> error, so why not return -ENOMEM as usual?
> > 
> > Fixed
> > 
> >>> +
> >>> +	for (i = 0; priv->hwmon_name[i]; i++)
> >>> +		if (hwmon_is_bad_char(priv->hwmon_name[i]))
> >>> +			priv->hwmon_name[i] = '_';

This is one reason to make a copy. You don't want to apply that to
main name of the device.

> >>> +
> >>> +	priv->hwmon_dev =
> >>> +		devm_hwmon_device_register_with_info(dev, priv->hwmon_name,
> >>> +						     phydev,
> >>> +						     &tja11xx_hwmon_chip_info,
> >>> +						     NULL);
> >>> +

The second reason is priv is released before dev, but what about
hwmon, especially if somebody has one of the files open? Is the
unregister synchronous?

	 Andrew

  reply	other threads:[~2018-12-23  9:59 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-21 23:35 [PATCH V3] net: phy: tja11xx: Add TJA11xx PHY driver Marek Vasut
2018-12-22 17:39 ` Heiner Kallweit
2018-12-23  9:16   ` Marek Vasut
2018-12-23  9:41     ` Heiner Kallweit
2018-12-23  9:59       ` Andrew Lunn [this message]
2018-12-23 10:21       ` Marek Vasut
2018-12-23 10:35         ` Andrew Lunn
2018-12-23 10:48           ` Marek Vasut
2019-01-03  2:09     ` Marek Vasut
2019-01-03  6:23       ` Heiner Kallweit
2019-01-04  2:19         ` Marek Vasut
2019-01-04  2:53           ` Marek Vasut
2019-01-04  2:57             ` Florian Fainelli
2019-01-04  5:40               ` Marek Vasut
2018-12-22 20:51 ` Heiner Kallweit
2018-12-23  9:13   ` Marek Vasut
2018-12-23 10:06   ` Andrew Lunn
2018-12-23 10:49     ` Marek Vasut
2018-12-23 10:58       ` Andrew Lunn
2018-12-23 11:00         ` Marek Vasut

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=20181223095940.GA31681@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=f.fainelli@gmail.com \
    --cc=hkallweit1@gmail.com \
    --cc=marex@denx.de \
    --cc=netdev@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).