lkml.org 
[lkml]   [2020]   [Mar]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v2 1/2] KEYS: Don't write out to userspace while holding key semaphore
From
Date
On 3/12/20 9:04 PM, Jarkko Sakkinen wrote:
> On Sun, Mar 08, 2020 at 01:04:09PM -0400, Waiman Long wrote:
>> + /*
>> + * Read methods will just return the required length
>> + * without any copying if the provided length isn't big
>> + * enough.
>> + */
>> + if ((ret > 0) && (ret <= buflen) && buffer &&
>> + copy_to_user(buffer, tmpbuf, ret))
>> + ret = -EFAULT;
> Please, reorg and remove redundant parentheses:
>
> /*
> * Read methods will just return the required length
> * without any copying if the provided length isn't big
> * enough.
> */
> if (ret > 0 && ret <= buflen) {
> if (buffer && copy_to_user(buffer, tmpbuf, ret))
> ret = -EFAULT;
> }
>
> Now the comment is attached to the exact right thing. The previous
> organization is a pain to look at when backtracking commits for
> whatever reason in the future.
Yes, I can reorganize the code.
> I'm also wondering, would it be possible to rework the code in a way
> that you don't have check whether buffer is valid on a constant basis?

One way to do that is to extract the down_read/up_read block into a
helper function and then have 2 separate paths - one for length
retrieval and another one for reading the key. I think that will make
the code a bit easier easier to read.

Thanks,
Longman

\
 
 \ /
  Last update: 2020-03-13 14:30    [W:0.062 / U:1.372 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site