[PATCH] jz_battery: improve driver code.

Lars-Peter Clausen lars at metafoo.de
Thu Sep 24 06:27:53 EDT 2009


Hi
> Hi, lars
>
> On Thu, Sep 24, 2009 at 2:02 PM, ZhangJieJing <kzjeef at gmail.com>
> wrote:
>> Hi,
>>
>> On Wed, Sep 23, 2009 at 9:11 PM, Lars-Peter Clausen
>> <lars at metafoo.de> wrote:
>>> Hi
>>>> 1. put all gobal var to a driver info struct.
>>> You solution is not exaclty what I had in mind. You are still
>>> using a global variable. I was talking about using
>>> {platform,dev}_{get,set}_drvdata to avoid it. Please take a
>>> look at how other drivers handle this.
>
> I change the static var to the drvdata.
>
> but I don't know how to get this ptr in static void
> jz_bat_work(struct work_struct *work) ?
>
> other function use blow function get drvdata ptr.
>
> static inline struct jz_battery_info *ps_to_jz_battery(struct
> power_supply *psy) { return container_of(psy, struct
> jz_battery_info, psy); }
>
> could give me some advice?
>
>
Sure. You can use containter_of there. work is a pointer to the
bat_work struct in jz_battery_info. Something like container_of(work,
struct jz_battery_info, bat_work) should do it.

- Lars
Hi
> Hi, lars
>
> On Thu, Sep 24, 2009 at 2:02 PM, ZhangJieJing <kzjeef at gmail.com>
> wrote:
>> Hi,
>>
>> On Wed, Sep 23, 2009 at 9:11 PM, Lars-Peter Clausen
>> <lars at metafoo.de> wrote:
>>> Hi
>>>> 1. put all gobal var to a driver info struct.
>>> You solution is not exaclty what I had in mind. You are still
>>> using a global variable. I was talking about using
>>> {platform,dev}_{get,set}_drvdata to avoid it. Please take a
>>> look at how other drivers handle this.
>
> I change the static var to the drvdata.
>
> but I don't know how to get this ptr in static void
> jz_bat_work(struct work_struct *work) ?
>
> other function use blow function get drvdata ptr.
>
> static inline struct jz_battery_info *ps_to_jz_battery(struct
> power_supply *psy) { return container_of(psy, struct
> jz_battery_info, psy); }
>
> could give me some advice?
>
>
Sure. You can use containter_of there. work is a pointer to the
bat_work struct in jz_battery_info. Something like container_of(work,
struct jz_battery_info, bat_work) should do it.

- Lars




More information about the discussion mailing list


interactive