On Tue, Feb 09, 2021 at 07:55:59AM -0800, Minchan Kim wrote: > On Tue, Feb 09, 2021 at 07:56:30AM +0100, Greg KH wrote: > > On Mon, Feb 08, 2021 at 10:34:51PM -0800, John Hubbard wrote: > > > On 2/8/21 10:27 PM, John Hubbard wrote: > > > > On 2/8/21 10:13 PM, Greg KH wrote: > > > > > On Mon, Feb 08, 2021 at 05:57:17PM -0800, John Hubbard wrote: > > > > > > On 2/8/21 3:36 PM, Minchan Kim wrote: > > > > > > ... > > > > > > > > > char name[CMA_MAX_NAME]; > > > > > > > > > +#ifdef CONFIG_CMA_SYSFS > > > > > > > > > + struct cma_stat *stat; > > > > > > > > > > > > > > > > This should not be a pointer. By making it a pointer, you've added a bunch of pointless > > > > > > > > extra code to the implementation. > > > > > > > > > > > > > > Originally, I went with the object lifetime with struct cma as you > > > > > > > suggested to make code simple. However, Greg KH wanted to have > > > > > > > release for kobj_type since it is consistent with other kboject > > > > > > > handling. > > > > > > > > > > > > Are you talking about the kobj in your new struct cma_stat? That seems > > > > > > like circular logic if so. I'm guessing Greg just wanted kobj methods > > > > > > to be used *if* you are dealing with kobjects. That's a narrower point. > > > > > > > > > > > > I can't imagine that he would have insisted on having additional > > > > > > allocations just so that kobj freeing methods could be used. :) > > > > > > > > > > Um, yes, I was :) > > > > > > > > > > You can not add a kobject to a structure and then somehow think you can > > > > > just ignore the reference counting issues involved. If a kobject is > > > > > part of a structure then the kobject is responsible for controling the > > > > > lifespan of the memory, nothing else can be. > > > > > > > > > > So by making the kobject dynamic, you properly handle that memory > > > > > lifespan of the object, instead of having to worry about the lifespan of > > > > > the larger object (which the original patch was not doing.) > > > > > > > > > > Does that make sense? > > > > > > > > > That part makes sense, yes, thanks. The part that I'm trying to straighten > > > > out is, why was kobject even added to the struct cma_stat in the first > > > > place? Why not just leave .stat as a static member variable, without > > > > a kobject in it, and done? > > > > > > > > > > Sorry, I think I get it now: this is in order to allow a separate lifetime > > > for the .stat member. I was sort of implicitly assuming that the "right" > > > way to do it is just have the whole object use one lifetime management, > > > but as you say, there is no kobject being added to the parent. > > > > > > I still feel odd about the allocation and freeing of something that seems > > > to be logically the same lifetime (other than perhaps a few, briefly pending > > > sysfs reads, at the end of life). So I'd still think that the kobject should > > > be added to the parent... > > sruct cma_stat { > spinlock_t lock; > unsigned long pages_attemtp; > unsigned long pages_fail; > }; > > struct cma { > .. > .. > struct kobject kobj; > struct cma_stat stat; > }; > > I guess this is what Johan suggested. I agree with it. > > > > > That's fine if you want to add it to the parent. If so, then the > > kobject controls the lifetime of the structure, nothing else can. > > The problem was parent object(i.e., struct cma cma_areas) is > static arrary so kobj->release function will be NULL or just > dummy. Is it okay? I thought it was one of the what you wanted > to avoid it. No, that is not ok. > > Either is fine with me, what is "forbidden" is having a kobject and > > somehow thinking that it does not control the lifetime of the structure. > > Since parent object is static arrary, there is no need to control the > lifetime so I am curious if parent object approach is okay from kobject > handling point of view. So the array is _NEVER_ freed? If not, fine, don't provide a release function for the kobject, but ick, just make a dynamic kobject I don't see the problem for something so tiny and not very many... I worry that any static kobject might be copied/pasted as someone might think this is an ok thing to do. And it's not an ok thing to do. thanks, greg k-h