Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1634381
| From | Rob Herring <robh@kernel.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH] tty: serdev: fix serdev_device_write return value |
| Date | 2017-05-02 14:40 +0200 |
| Message-ID | <tCFfY-6Iv-19@gated-at.bofh.it> (permalink) |
| References | <tCtHP-7sj-1@gated-at.bofh.it> <tCCi6-4Jn-25@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Tue, May 2, 2017 at 4:25 AM, Johan Hovold <johan@kernel.org> wrote:
> On Mon, May 01, 2017 at 07:17:14PM -0500, Rob Herring wrote:
>> Commit 6fe729c4bdae ("serdev: Add serdev_device_write subroutine")
>> provides a compatibility wrapper for the existing
>> serdev_device_write_buf, but it fails to return the number of bytes
>> written causing users to timeout.
>
> So this would also be fixed for serdev_device_write_buf() by Stefan
> Wahren's patch restoring that function implementation, but returning the
> amount written is perhaps desirable also for blocking writes for
> consistency reasons.
Yes, I saw it after I wrote this. We should apply both IMO.
>> Fixes: 6fe729c4bdae ("serdev: Add serdev_device_write subroutine")
>> Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> Signed-off-by: Rob Herring <robh@kernel.org>
>> ---
>> drivers/tty/serdev/core.c | 5 +++--
>> 1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c
>> index 433de5ea9b02..ccfe56355c4f 100644
>> --- a/drivers/tty/serdev/core.c
>> +++ b/drivers/tty/serdev/core.c
>> @@ -127,7 +127,7 @@ int serdev_device_write(struct serdev_device *serdev,
>> unsigned long timeout)
>> {
>> struct serdev_controller *ctrl = serdev->ctrl;
>> - int ret;
>> + int ret, wr_cnt = 0;
>>
>> if (!ctrl || !ctrl->ops->write_buf ||
>> (timeout && !serdev->ops->write_wakeup))
>> @@ -143,12 +143,13 @@ int serdev_device_write(struct serdev_device *serdev,
>>
>> buf += ret;
>> count -= ret;
>> + wr_cnt += ret;
>>
>> } while (count &&
>> (timeout = wait_for_completion_timeout(&serdev->write_comp,
>> timeout)));
>>
>> mutex_unlock(&serdev->write_lock);
>> - return ret < 0 ? ret : (count ? -ETIMEDOUT : 0);
>> + return ret < 0 ? ret : (count ? -ETIMEDOUT : wr_cnt);
>
> That's some nasty use of the ternary operator. Ditching it completely
> would be more readable.
>
> if (ret < 0)
> return ret;
>
> if (count)
> return -ETIMEDOUT;
>
> return wr_count;
>
> and here wr_count is the value of count passed to the function (and
> could just be stored on entry instead).
Okay.
I'll wait for Greg to apply Stefan's patch and respin on top of it.
Rob
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH] tty: serdev: fix serdev_device_write return value Rob Herring <robh@kernel.org> - 2017-05-02 02:20 +0200
Re: [PATCH] tty: serdev: fix serdev_device_write return value Johan Hovold <johan@kernel.org> - 2017-05-02 11:30 +0200
Re: [PATCH] tty: serdev: fix serdev_device_write return value Rob Herring <robh@kernel.org> - 2017-05-02 14:40 +0200
Re: [PATCH] tty: serdev: fix serdev_device_write return value Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-05-03 19:50 +0200
Re: [PATCH] tty: serdev: fix serdev_device_write return value Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-05-03 20:10 +0200
csiph-web