Prefer __containerof() over __member2struct().

The former works better with qualifiers, but also properly type checks
the input pointer.
This commit is contained in:
Ed Schouten 2012-10-19 13:26:40 +00:00
parent 4c0d7cdf5d
commit 6b946662d9
5 changed files with 8 additions and 7 deletions

View File

@ -142,7 +142,8 @@ void t3_process_tid_release_list(void *data, int pending);
static inline struct tom_data *
t3_tomdata(struct toedev *tod)
{
return (member2struct(tom_data, tod, tod));
return (__containerof(tod, struct tom_data, tod));
}
union listen_entry {

View File

@ -435,7 +435,7 @@ static inline struct sge_rxq *
iq_to_rxq(struct sge_iq *iq)
{
return (member2struct(sge_rxq, iq, iq));
return (__containerof(iq, struct sge_rxq, iq));
}
@ -450,7 +450,7 @@ static inline struct sge_ofld_rxq *
iq_to_ofld_rxq(struct sge_iq *iq)
{
return (member2struct(sge_ofld_rxq, iq, iq));
return (__containerof(iq, struct sge_ofld_rxq, iq));
}
#endif

View File

@ -94,7 +94,7 @@ int do_l2t_write_rpl(struct sge_iq *, const struct rss_header *, struct mbuf *);
static inline void
t4_l2t_release(struct l2t_entry *e)
{
struct l2t_data *d = member2struct(l2t_data, l2tab[e->idx], e);
struct l2t_data *d = __containerof(e, struct l2t_data, l2tab[e->idx]);
if (atomic_fetchadd_int(&e->refcnt, -1) == 1)
atomic_add_int(&d->nfree, 1);

View File

@ -3057,8 +3057,8 @@ t4_register_an_handler(struct adapter *sc, an_handler_t h)
static int
fw_msg_not_handled(struct adapter *sc, const __be64 *rpl)
{
__be64 *r = __DECONST(__be64 *, rpl);
struct cpl_fw6_msg *cpl = member2struct(cpl_fw6_msg, data, r);
const struct cpl_fw6_msg *cpl =
__containerof(rpl, struct cpl_fw6_msg, data[0]);
#ifdef INVARIANTS
panic("%s: fw_msg type %d", __func__, cpl->type);

View File

@ -205,7 +205,7 @@ static inline struct tom_data *
tod_td(struct toedev *tod)
{
return (member2struct(tom_data, tod, tod));
return (__containerof(tod, struct tom_data, tod));
}
static inline struct adapter *