2021-11-29 22:48:38

by Philipp Hortmann

[permalink] [raw]
Subject: [PATCH 0/4] Docs: usb: Code and text updates from usb-skeleton

Explanation and example code updates from usb-skeleton

Philipp Hortmann (4):
Docs: usb: update usb_bulk_msg receiving example
Docs: usb: update comment and code near decrement our usage count for
the device
Docs: usb: update comment and code of function skel_delete
Docs: usb: update explanation for device_present to disconnected

.../driver-api/usb/writing_usb_driver.rst | 69 +++++++++----------
1 file changed, 33 insertions(+), 36 deletions(-)

--
2.25.1



2021-11-29 22:51:04

by Philipp Hortmann

[permalink] [raw]
Subject: [PATCH 1/4] Docs: usb: update usb_bulk_msg receiving example

Clarification that this example is not in the driver template anymore.
Update code example so that it fits best to usb-skeleton.c

Signed-off-by: Philipp Hortmann <[email protected]>
---
.../driver-api/usb/writing_usb_driver.rst | 30 +++++++++----------
1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/Documentation/driver-api/usb/writing_usb_driver.rst b/Documentation/driver-api/usb/writing_usb_driver.rst
index b43e1ce49f0e..a9608ad18d77 100644
--- a/Documentation/driver-api/usb/writing_usb_driver.rst
+++ b/Documentation/driver-api/usb/writing_usb_driver.rst
@@ -218,36 +218,36 @@ do very much processing at that time. Our implementation of
``skel_write_bulk_callback`` merely reports if the urb was completed
successfully or not and then returns.

-The read function works a bit differently from the write function in
+This read function works a bit differently from the write function in
that we do not use an urb to transfer data from the device to the
-driver. Instead we call the :c:func:`usb_bulk_msg` function, which can be used
+driver. Instead we call `usb_bulk_msg` function, which can be used
to send or receive data from a device without having to create urbs and
-handle urb completion callback functions. We call the :c:func:`usb_bulk_msg`
+handle urb completion callback functions. We call `usb_bulk_msg`
function, giving it a buffer into which to place any data received from
the device and a timeout value. If the timeout period expires without
receiving any data from the device, the function will fail and return an
error message. This can be shown with the following code::

/* do an immediate bulk read to get data from the device */
- retval = usb_bulk_msg (skel->dev,
- usb_rcvbulkpipe (skel->dev,
- skel->bulk_in_endpointAddr),
- skel->bulk_in_buffer,
- skel->bulk_in_size,
- &count, 5000);
+ rv = usb_bulk_msg(dev->udev,
+ usb_rcvbulkpipe (dev->udev,
+ dev->bulk_in_endpointAddr),
+ dev->bulk_in_buffer,
+ dev->bulk_in_size,
+ &len, 5000);
/* if the read was successful, copy the data to user space */
- if (!retval) {
- if (copy_to_user (buffer, skel->bulk_in_buffer, count))
- retval = -EFAULT;
+ if (!rv) {
+ if (copy_to_user (buffer, dev->bulk_in_buffer, len))
+ rv = -EFAULT;
else
- retval = count;
+ rv = len;
}


-The :c:func:`usb_bulk_msg` function can be very useful for doing single reads
+Function `usb_bulk_msg` can be very useful for doing single reads
or writes to a device; however, if you need to read or write constantly to
a device, it is recommended to set up your own urbs and submit them to
-the USB subsystem.
+the USB subsystem. The template uses urbs for read and write.

When the user program releases the file handle that it has been using to
talk to the device, the release function in the driver is called. In
--
2.25.1


2021-11-29 22:51:08

by Philipp Hortmann

[permalink] [raw]
Subject: [PATCH 4/4] Docs: usb: update explanation for device_present to disconnected

Update text for `device_present` flag to `disconnected` flag

Signed-off-by: Philipp Hortmann <[email protected]>
---
.../driver-api/usb/writing_usb_driver.rst | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/Documentation/driver-api/usb/writing_usb_driver.rst b/Documentation/driver-api/usb/writing_usb_driver.rst
index 74bb72a2f0ac..d398d2155cd3 100644
--- a/Documentation/driver-api/usb/writing_usb_driver.rst
+++ b/Documentation/driver-api/usb/writing_usb_driver.rst
@@ -277,15 +277,13 @@ notify the user-space programs that the device is no longer there. The
}


-If a program currently has an open handle to the device, we reset the
-flag ``device_present``. For every read, write, release and other
+If the driver probed the device successfully, the flag ``disconnected``
+is initialized and set to false. For every read, write and other
functions that expect a device to be present, the driver first checks
-this flag to see if the device is still present. If not, it releases
-that the device has disappeared, and a ``-ENODEV`` error is returned to the
-user-space program. When the release function is eventually called, it
-determines if there is no device and if not, it does the cleanup that
-the ``skel_disconnect`` function normally does if there are no open files
-on the device (see Listing 5).
+this flag to see if the device is still present. If not, a ``-ENODEV``
+error is returned to the user-space program. When the device is
+disconnected, `skel_disconnected` function is called. It sets ``disconnected``
+to true and cleans up.

Isochronous Data
================
--
2.25.1


2021-11-29 22:53:27

by Philipp Hortmann

[permalink] [raw]
Subject: [PATCH 2/4] Docs: usb: update comment and code near decrement our usage count for the device

Put release function in the document typical form
Update comment: decrement our usage count ..
and code according to usb-skeleton.c

Signed-off-by: Philipp Hortmann <[email protected]>
---
Documentation/driver-api/usb/writing_usb_driver.rst | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Documentation/driver-api/usb/writing_usb_driver.rst b/Documentation/driver-api/usb/writing_usb_driver.rst
index a9608ad18d77..b16e4e76d472 100644
--- a/Documentation/driver-api/usb/writing_usb_driver.rst
+++ b/Documentation/driver-api/usb/writing_usb_driver.rst
@@ -250,12 +250,12 @@ a device, it is recommended to set up your own urbs and submit them to
the USB subsystem. The template uses urbs for read and write.

When the user program releases the file handle that it has been using to
-talk to the device, the release function in the driver is called. In
+talk to the device, the `skel_release` function in the driver is called. In
this function we decrement our private usage count and wait for possible
pending writes::

- /* decrement our usage count for the device */
- --skel->open_count;
+ /* decrement the count on our device */
+ kref_put(&dev->kref, skel_delete);


One of the more difficult problems that USB drivers must be able to
--
2.25.1


2021-11-30 20:10:35

by Alan Stern

[permalink] [raw]
Subject: Re: [PATCH 1/4] Docs: usb: update usb_bulk_msg receiving example

On Mon, Nov 29, 2021 at 09:21:41PM +0100, Philipp Hortmann wrote:
> Clarification that this example is not in the driver template anymore.
> Update code example so that it fits best to usb-skeleton.c
>
> Signed-off-by: Philipp Hortmann <[email protected]>
> ---
> .../driver-api/usb/writing_usb_driver.rst | 30 +++++++++----------
> 1 file changed, 15 insertions(+), 15 deletions(-)
>
> diff --git a/Documentation/driver-api/usb/writing_usb_driver.rst b/Documentation/driver-api/usb/writing_usb_driver.rst
> index b43e1ce49f0e..a9608ad18d77 100644
> --- a/Documentation/driver-api/usb/writing_usb_driver.rst
> +++ b/Documentation/driver-api/usb/writing_usb_driver.rst
> @@ -218,36 +218,36 @@ do very much processing at that time. Our implementation of
> ``skel_write_bulk_callback`` merely reports if the urb was completed
> successfully or not and then returns.
>
> -The read function works a bit differently from the write function in
> +This read function works a bit differently from the write function in
> that we do not use an urb to transfer data from the device to the
> -driver. Instead we call the :c:func:`usb_bulk_msg` function, which can be used
> +driver. Instead we call `usb_bulk_msg` function, which can be used
> to send or receive data from a device without having to create urbs and
> -handle urb completion callback functions. We call the :c:func:`usb_bulk_msg`
> +handle urb completion callback functions. We call `usb_bulk_msg`
> function, giving it a buffer into which to place any data received from

The reason for the last two changes above isn't clear. You removed some of the
markup indicators and made the text ungrammatical. This does not seem like an
improvement.

Alan Stern

> the device and a timeout value. If the timeout period expires without
> receiving any data from the device, the function will fail and return an
> error message. This can be shown with the following code::
>
> /* do an immediate bulk read to get data from the device */
> - retval = usb_bulk_msg (skel->dev,
> - usb_rcvbulkpipe (skel->dev,
> - skel->bulk_in_endpointAddr),
> - skel->bulk_in_buffer,
> - skel->bulk_in_size,
> - &count, 5000);
> + rv = usb_bulk_msg(dev->udev,
> + usb_rcvbulkpipe (dev->udev,
> + dev->bulk_in_endpointAddr),
> + dev->bulk_in_buffer,
> + dev->bulk_in_size,
> + &len, 5000);
> /* if the read was successful, copy the data to user space */
> - if (!retval) {
> - if (copy_to_user (buffer, skel->bulk_in_buffer, count))
> - retval = -EFAULT;
> + if (!rv) {
> + if (copy_to_user (buffer, dev->bulk_in_buffer, len))
> + rv = -EFAULT;
> else
> - retval = count;
> + rv = len;
> }
>
>
> -The :c:func:`usb_bulk_msg` function can be very useful for doing single reads
> +Function `usb_bulk_msg` can be very useful for doing single reads
> or writes to a device; however, if you need to read or write constantly to
> a device, it is recommended to set up your own urbs and submit them to
> -the USB subsystem.
> +the USB subsystem. The template uses urbs for read and write.
>
> When the user program releases the file handle that it has been using to
> talk to the device, the release function in the driver is called. In
> --
> 2.25.1
>

2021-12-02 04:49:59

by Philipp Hortmann

[permalink] [raw]
Subject: Re: [PATCH 1/4] Docs: usb: update usb_bulk_msg receiving example

On 11/30/21 9:10 PM, Alan Stern wrote:
> On Mon, Nov 29, 2021 at 09:21:41PM +0100, Philipp Hortmann wrote:
>> Clarification that this example is not in the driver template anymore.
>> Update code example so that it fits best to usb-skeleton.c
>>
>> Signed-off-by: Philipp Hortmann <[email protected]>
>> ---
>> .../driver-api/usb/writing_usb_driver.rst | 30 +++++++++----------
>> 1 file changed, 15 insertions(+), 15 deletions(-)
>>
>> diff --git a/Documentation/driver-api/usb/writing_usb_driver.rst b/Documentation/driver-api/usb/writing_usb_driver.rst
>> index b43e1ce49f0e..a9608ad18d77 100644
>> --- a/Documentation/driver-api/usb/writing_usb_driver.rst
>> +++ b/Documentation/driver-api/usb/writing_usb_driver.rst
>> @@ -218,36 +218,36 @@ do very much processing at that time. Our implementation of
>> ``skel_write_bulk_callback`` merely reports if the urb was completed
>> successfully or not and then returns.
>>
>> -The read function works a bit differently from the write function in
>> +This read function works a bit differently from the write function in
>> that we do not use an urb to transfer data from the device to the
>> -driver. Instead we call the :c:func:`usb_bulk_msg` function, which can be used
>> +driver. Instead we call `usb_bulk_msg` function, which can be used
>> to send or receive data from a device without having to create urbs and
>> -handle urb completion callback functions. We call the :c:func:`usb_bulk_msg`
>> +handle urb completion callback functions. We call `usb_bulk_msg`
>> function, giving it a buffer into which to place any data received from
>
> The reason for the last two changes above isn't clear. You removed some of the
> markup indicators and made the text ungrammatical. This does not seem like an
> improvement.
>
> Alan Stern
>
This two changes were made because of an earlier comment to the same
document, but may be I understood this wrong:
On 10/19/21 11:17 PM, Jonathan Corbet wrote:
...
We shouldn't be using :c:func: anymore; just say usb_register() and the
right things will happen. Definitely worth fixing while you are in the
neighborhood.
...
If you're making this change, take out "the" (as well as :c:func:).
...
___
Please find the full email under the link:
https://lore.kernel.org/linux-usb/[email protected]/T/

Please give me an example for the right wording. I am not a native
English speaker. Is the article in this case required?
Thanks for your support.
Philipp Hortmann

2021-12-02 19:49:11

by Alan Stern

[permalink] [raw]
Subject: Re: [PATCH 1/4] Docs: usb: update usb_bulk_msg receiving example

On Thu, Dec 02, 2021 at 05:49:47AM +0100, Philipp Hortmann wrote:
> On 11/30/21 9:10 PM, Alan Stern wrote:
> > On Mon, Nov 29, 2021 at 09:21:41PM +0100, Philipp Hortmann wrote:
> > > Clarification that this example is not in the driver template anymore.
> > > Update code example so that it fits best to usb-skeleton.c
> > >
> > > Signed-off-by: Philipp Hortmann <[email protected]>
> > > ---
> > > .../driver-api/usb/writing_usb_driver.rst | 30 +++++++++----------
> > > 1 file changed, 15 insertions(+), 15 deletions(-)
> > >
> > > diff --git a/Documentation/driver-api/usb/writing_usb_driver.rst b/Documentation/driver-api/usb/writing_usb_driver.rst
> > > index b43e1ce49f0e..a9608ad18d77 100644
> > > --- a/Documentation/driver-api/usb/writing_usb_driver.rst
> > > +++ b/Documentation/driver-api/usb/writing_usb_driver.rst
> > > @@ -218,36 +218,36 @@ do very much processing at that time. Our implementation of
> > > ``skel_write_bulk_callback`` merely reports if the urb was completed
> > > successfully or not and then returns.
> > > -The read function works a bit differently from the write function in
> > > +This read function works a bit differently from the write function in
> > > that we do not use an urb to transfer data from the device to the
> > > -driver. Instead we call the :c:func:`usb_bulk_msg` function, which can be used
> > > +driver. Instead we call `usb_bulk_msg` function, which can be used
> > > to send or receive data from a device without having to create urbs and
> > > -handle urb completion callback functions. We call the :c:func:`usb_bulk_msg`
> > > +handle urb completion callback functions. We call `usb_bulk_msg`
> > > function, giving it a buffer into which to place any data received from
> >
> > The reason for the last two changes above isn't clear. You removed some of the
> > markup indicators and made the text ungrammatical. This does not seem like an
> > improvement.
> >
> > Alan Stern
> >
> This two changes were made because of an earlier comment to the same
> document, but may be I understood this wrong:
> On 10/19/21 11:17 PM, Jonathan Corbet wrote:
> ...
> We shouldn't be using :c:func: anymore; just say usb_register() and the
> right things will happen. Definitely worth fixing while you are in the
> neighborhood.
> ...
> If you're making this change, take out "the" (as well as :c:func:).
> ...
> ___
> Please find the full email under the link:
> https://lore.kernel.org/linux-usb/[email protected]/T/
>
> Please give me an example for the right wording. I am not a native English
> speaker. Is the article in this case required?

Okay, now I see what's going on. You should change it like this:

-driver. Instead we call the :c:func:`usb_bulk_msg` function, which can be used
+driver. Instead we call `usb_bulk_msg`, which can be used
to send or receive data from a device without having to create urbs and
-handle urb completion callback functions. We call the :c:func:`usb_bulk_msg`
+handle urb completion callback functions. We call `usb_bulk_msg`,
giving it a buffer into which to place any data received from

Alan Stern

2021-12-03 02:01:56

by Akira Yokosawa

[permalink] [raw]
Subject: Re: [PATCH 1/4] Docs: usb: update usb_bulk_msg receiving example

Hi,

On Thu, 2 Dec 2021 14:49:08 -0500, Alan Stern wrote:
> On Thu, Dec 02, 2021 at 05:49:47AM +0100, Philipp Hortmann wrote:
[...]
>> Please find the full email under the link:
>> https://lore.kernel.org/linux-usb/[email protected]/T/
>>
>> Please give me an example for the right wording. I am not a native English
>> speaker. Is the article in this case required?
>
> Okay, now I see what's going on. You should change it like this:
>
> -driver. Instead we call the :c:func:`usb_bulk_msg` function, which can be used
> +driver. Instead we call `usb_bulk_msg`, which can be used
> to send or receive data from a device without having to create urbs and
> -handle urb completion callback functions. We call the :c:func:`usb_bulk_msg`
> +handle urb completion callback functions. We call `usb_bulk_msg`,
> giving it a buffer into which to place any data received from

Well, for function names to be caught by kernel-doc tools,
you need to say usb_bulk_msg() (without ``, with () appended).

So, the diff should look:

-driver. Instead we call the :c:func:`usb_bulk_msg` function, which can be used
+driver. Instead we call usb_bulk_msg(), which can be used
to send or receive data from a device without having to create urbs and
-handle urb completion callback functions. We call the :c:func:`usb_bulk_msg`
+handle urb completion callback functions. We call usb_bulk_msg(),
giving it a buffer into which to place any data received from

You can find related documentation at:

https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#cross-referencing-from-restructuredtext

Thanks, Akira

>
> Alan Stern