lkml.org 
[lkml]   [2012]   [Mar]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v6 2/2] Regulator: Add Anatop regulator driver
On Sun, Mar 04, 2012 at 02:51:48PM +0800, Shawn Guo wrote:

> > + sreg = devm_kzalloc(dev, sizeof(struct anatop_regulator), GFP_KERNEL);
> > + if (!sreg)
> > + return -EINVAL;
> > + rdesc = devm_kzalloc(dev, sizeof(struct regulator_desc), GFP_KERNEL);
> > + if (!rdesc)
> > + return -EINVAL;

> Would something like the following be better?

> sreg = devm_kzalloc(dev, sizeof(*sreg) + sizeof(*rdesc), GFP_KERNEL);
> if (!sreg)
> return -ENOMEM;
> rdesc = (struct regulator_desc *)(sreg + 1);

No, that sort of pointer arithmetic would be much worse - it's harder to
read and more likely to break. However, embedding the regulator_desc in
sreg would achieve the same result without the legibility issues.
[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2012-03-04 14:33    [W:0.322 / U:0.072 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site