Re: [PATCH v2 6/9] debugfs: Implement debugfs_create_str()
From: Greg KH
Date: Sat Mar 27 2021 - 06:41:43 EST
On Fri, Mar 26, 2021 at 04:19:12PM +0100, Peter Zijlstra wrote:
> On Fri, Mar 26, 2021 at 03:58:37PM +0100, Rasmus Villemoes wrote:
> > > kmalloc(len + 2, ...);
> >
> > No, because nul-terminating the stuff you pass to
> > simple_read_from_buffer is pointless cargo-culting. Yeah, read_file_bool
> > does it, but that's just bogus.
>
> Urgh, feel yuck to not have it zero terminated, but if you feel strongly
> about it I suppose I can make it go away.
>
> > > len = strscpy(copy, str, len);
> > > if (len < 0)
> > > return len;
> >
> > To what end? The only way that could possibly return -EFOO is if the
> > nul-terminator in str vanished between the strlen() and here, and in
> > that case you have bigger problems.
>
> There are strings in the kernel which we rewrite in most ugly ways,
> task_struct::comm comes to mind. Best be paranoid.
>
> > > Copy-pasta from debugfs_*_bool(). This thing seems to export everything
> > > and I figured I'd go along with that.
> >
> > I thought the convention was not to export anything until the kernel
> > itself had a (modular) user.
>
> That's generally how I feel too. But this really isn't my subsystem so I
> more or less try to mimmick what I see done there.
I'll take some time next week and go through and remove any exports in
debugfs that are not actually needed for exports as it's been a while
since I last looked...
But that should not affect this change, it's fine to me as-is.
thanks,
greg k-h