udev: use container_of() macro

This commit is contained in:
Lucas De Marchi 2012-04-26 13:36:02 -03:00 committed by Kay Sievers
parent c4326aa4af
commit b27ee00bf5
3 changed files with 8 additions and 24 deletions

View file

@ -80,13 +80,9 @@ void udev_list_node_remove(struct udev_list_node *entry)
} }
/* return list entry which embeds this node */ /* return list entry which embeds this node */
static struct udev_list_entry *list_node_to_entry(struct udev_list_node *node) static inline struct udev_list_entry *list_node_to_entry(struct udev_list_node *node)
{ {
char *list; return container_of(node, struct udev_list_entry, node);
list = (char *)node;
list -= offsetof(struct udev_list_entry, node);
return (struct udev_list_entry *)list;
} }
void udev_list_init(struct udev *udev, struct udev_list *list, bool unique) void udev_list_init(struct udev *udev, struct udev_list *list, bool unique)

View file

@ -55,13 +55,9 @@ static int debug;
/* This can increase dynamically */ /* This can increase dynamically */
static size_t bufsize = BUFSIZE; static size_t bufsize = BUFSIZE;
static struct _mate *node_to_mate(struct udev_list_node *node) static inline struct _mate *node_to_mate(struct udev_list_node *node)
{ {
char *mate; return container_of(node, struct _mate, node);
mate = (char *)node;
mate -= offsetof(struct _mate, node);
return (struct _mate *)mate;
} }
static void sig_alrm(int signo) static void sig_alrm(int signo)

View file

@ -99,13 +99,9 @@ struct event {
int ifindex; int ifindex;
}; };
static struct event *node_to_event(struct udev_list_node *node) static inline struct event *node_to_event(struct udev_list_node *node)
{ {
char *event; return container_of(node, struct event, node);
event = (char *)node;
event -= offsetof(struct event, node);
return (struct event *)event;
} }
static void event_queue_cleanup(struct udev *udev, enum event_state type); static void event_queue_cleanup(struct udev *udev, enum event_state type);
@ -134,13 +130,9 @@ struct worker_message {
int exitcode; int exitcode;
}; };
static struct worker *node_to_worker(struct udev_list_node *node) static inline struct worker *node_to_worker(struct udev_list_node *node)
{ {
char *worker; return container_of(node, struct worker, node);
worker = (char *)node;
worker -= offsetof(struct worker, node);
return (struct worker *)worker;
} }
static void event_queue_delete(struct event *event, bool export) static void event_queue_delete(struct event *event, bool export)