lkml.org 
[lkml]   [2022]   [May]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] gfs2: Use container_of() for gfs2_glock(aspace)
> +/* gfs2_glock_get(), "glock" must be first. */
> +struct glock_aspace {
> + struct gfs2_glock glock;
> + struct address_space mapping;
> +};

Why does glock need to be first? The whole point of using container_of
is that we don't have to make that assumption.

> static inline struct address_space *gfs2_glock2aspace(struct gfs2_glock *gl)
> {
> if (gl->gl_ops->go_flags & GLOF_ASPACE)
> - return (struct address_space *)(gl + 1);
> + return &(container_of(gl, struct glock_aspace, glock)->mapping);

Do we even need the braces here?

> struct inode *inode = mapping->host;
> if (mapping->a_ops == &gfs2_meta_aops)
> - return (((struct gfs2_glock *)mapping) - 1)->gl_name.ln_sbd;
> + return container_of(mapping, struct glock_aspace, mapping)->glock.gl_name.ln_sbd;

A local variable would be really nice for the reader here to decompose
this a bit:

struct glock_aspace *a =
container_of(mapping, struct glock_aspace, mapping);

return a->glock.gl_name.ln_sbd;

\
 
 \ /
  Last update: 2022-05-10 09:34    [W:0.095 / U:0.008 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site