lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Sat, 16 May 2009 08:57:03 +0200
From:	Wolfgang Grandegger <wg@...ndegger.com>
To:	Jonathan Corbet <corbet@....net>
CC:	netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
	Oliver Hartkopp <oliver.hartkopp@...kswagen.de>
Subject: Re: [PATCH v2 4/7] [PATCH 4/8] can: Driver for the SJA1000 CAN controller

Wolfgang Grandegger wrote:
> Jonathan Corbet wrote:
>> On Thu, 14 May 2009 11:03:53 +0200
>> Wolfgang Grandegger <wg@...ndegger.com> wrote:
>>
>>>> So you're still using the "put the higher-level structure at the top so we
>>>> can treat it like either kind of pointer" trick.  I'd still recommend
>>>> against that.  Far better to do something like:
>>>>
>>>> 	struct can_priv *canpriv = netdev_priv(dev);
>>>> 	struct sja_1000_priv *priv = container_of(canpriv, struct sja_1000_priv, can);
>>>>
>>>> Of course, you can put that dance into a helper function.  
>>> There is no way to initialize the value returned by netdev_priv() as it
>>> does not point to a member of struct net_device. I already commented here:
>>>
>>>   http://marc.info/?l=linux-netdev&m=124120212106891&w=2
>>>
>>> Have I missed something?
>> I'm confused.  It points to the struct can_priv that you registered at
>> the beginning.  Since that structure is contained within struct
>> sja1000_priv, you can use container_of(), as described above, to get
>> it.
>>
>> I would probably just write something like:
>>
>> static inline struct sja1000_priv *to_sja1000_priv(struct net_device *dev)
>> {
>> 	return container_of(netdev_priv(dev), struct sja1000_priv, can);
>> }
>>
>> So have *I* missed something?
> 
> Furthermore, the higher layer needs to known the location of the member
> "struct sja1000_priv can", e.g. by defining:
> 
>   dev->priv = &dev_specific_priv->can;
> 
> But "struct net_device" does not have a "priv" member. netdev_priv(dev)
> always points to the beginning of the private data area. See:
> 
>    http://lxr.linux.no/linux+v2.6.29/include/linux/netdevice.h#L953

I could use container_of() as you suggested, of course, if the "struct
can_priv" remains the first member of  "struct sja1000_priv". Would that
already be an improvement?

Wolfgang.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ