linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] Docs: usb: Example code updates from usb-skeleton
@ 2021-10-29 19:39 Philipp Hortmann
  2021-10-29 19:39 ` [PATCH 1/3] Docs: usb: update err() to pr_err() and replace __FILE__ Philipp Hortmann
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Philipp Hortmann @ 2021-10-29 19:39 UTC (permalink / raw)
  To: corbet, linux-doc, linux-kernel; +Cc: linux-usb

Example code updates from usb-skeleton.c

Philipp Hortmann (3):
  Docs: usb: update err() to pr_err() and replace __FILE__
  Docs: usb: update comment and code near increment usage count
  Docs: usb: update writesize, copy_from_user, usb_fill_bulk_urb,
    usb_submit_urb

 .../driver-api/usb/writing_usb_driver.rst     | 32 ++++++++++---------
 1 file changed, 17 insertions(+), 15 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] Docs: usb: update err() to pr_err() and replace __FILE__
  2021-10-29 19:39 [PATCH 0/3] Docs: usb: Example code updates from usb-skeleton Philipp Hortmann
@ 2021-10-29 19:39 ` Philipp Hortmann
  2021-10-29 20:33   ` Sergey Shtylyov
  2021-10-29 19:39 ` [PATCH 2/3] Docs: usb: update comment and code near increment usage count Philipp Hortmann
  2021-10-29 19:40 ` [PATCH 3/3] Docs: usb: update writesize, copy_from_user, usb_fill_bulk_urb, usb_submit_urb Philipp Hortmann
  2 siblings, 1 reply; 6+ messages in thread
From: Philipp Hortmann @ 2021-10-29 19:39 UTC (permalink / raw)
  To: corbet, linux-doc, linux-kernel; +Cc: linux-usb

update err() to pr_err() and replace __FILE__

Signed-off-by: Philipp Hortmann <philipp.g.hortmann@gmail.com>
---
 Documentation/driver-api/usb/writing_usb_driver.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/driver-api/usb/writing_usb_driver.rst b/Documentation/driver-api/usb/writing_usb_driver.rst
index 2176297e5765..5c29e5bdbe88 100644
--- a/Documentation/driver-api/usb/writing_usb_driver.rst
+++ b/Documentation/driver-api/usb/writing_usb_driver.rst
@@ -91,8 +91,8 @@ usually in the driver's init function, as shown here::
 	    /* register this driver with the USB subsystem */
 	    result = usb_register(&skel_driver);
 	    if (result < 0) {
-		    err("usb_register failed for the "__FILE__ "driver."
-			"Error number %d", result);
+		    pr_err("usb_register failed for the %s driver. "
+			   "Error number %d", skel_driver.name, result);
 		    return -1;
 	    }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] Docs: usb: update comment and code near increment usage count
  2021-10-29 19:39 [PATCH 0/3] Docs: usb: Example code updates from usb-skeleton Philipp Hortmann
  2021-10-29 19:39 ` [PATCH 1/3] Docs: usb: update err() to pr_err() and replace __FILE__ Philipp Hortmann
@ 2021-10-29 19:39 ` Philipp Hortmann
  2021-10-29 19:40 ` [PATCH 3/3] Docs: usb: update writesize, copy_from_user, usb_fill_bulk_urb, usb_submit_urb Philipp Hortmann
  2 siblings, 0 replies; 6+ messages in thread
From: Philipp Hortmann @ 2021-10-29 19:39 UTC (permalink / raw)
  To: corbet, linux-doc, linux-kernel; +Cc: linux-usb

update comment: increment our usage count ..
and code according to usb-skeleton.c

Signed-off-by: Philipp Hortmann <philipp.g.hortmann@gmail.com>
---
 Documentation/driver-api/usb/writing_usb_driver.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/driver-api/usb/writing_usb_driver.rst b/Documentation/driver-api/usb/writing_usb_driver.rst
index 5c29e5bdbe88..14eda0342649 100644
--- a/Documentation/driver-api/usb/writing_usb_driver.rst
+++ b/Documentation/driver-api/usb/writing_usb_driver.rst
@@ -167,8 +167,8 @@ structure. This is done so that future calls to file operations will
 enable the driver to determine which device the user is addressing. All
 of this is done with the following code::
 
-    /* increment our usage count for the module */
-    ++skel->open_count;
+    /* increment our usage count for the device */
+    kref_get(&dev->kref);
 
     /* save our object in the file's private structure */
     file->private_data = dev;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] Docs: usb: update writesize, copy_from_user, usb_fill_bulk_urb, usb_submit_urb
  2021-10-29 19:39 [PATCH 0/3] Docs: usb: Example code updates from usb-skeleton Philipp Hortmann
  2021-10-29 19:39 ` [PATCH 1/3] Docs: usb: update err() to pr_err() and replace __FILE__ Philipp Hortmann
  2021-10-29 19:39 ` [PATCH 2/3] Docs: usb: update comment and code near increment usage count Philipp Hortmann
@ 2021-10-29 19:40 ` Philipp Hortmann
  2 siblings, 0 replies; 6+ messages in thread
From: Philipp Hortmann @ 2021-10-29 19:40 UTC (permalink / raw)
  To: corbet, linux-doc, linux-kernel; +Cc: linux-usb

update code examples writesize, copy_from_user, usb_fill_bulk_urb,
usb_submit_urb in skel_write() according to usb-skeleton.c

Signed-off-by: Philipp Hortmann <philipp.g.hortmann@gmail.com>
---
 .../driver-api/usb/writing_usb_driver.rst     | 24 ++++++++++---------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/Documentation/driver-api/usb/writing_usb_driver.rst b/Documentation/driver-api/usb/writing_usb_driver.rst
index 14eda0342649..02c28ee10b91 100644
--- a/Documentation/driver-api/usb/writing_usb_driver.rst
+++ b/Documentation/driver-api/usb/writing_usb_driver.rst
@@ -185,24 +185,26 @@ space, points the urb to the data and submits the urb to the USB
 subsystem. This can be seen in the following code::
 
     /* we can only write as much as 1 urb will hold */
-    bytes_written = (count > skel->bulk_out_size) ? skel->bulk_out_size : count;
+    size_t writesize = min_t(size_t, count, MAX_TRANSFER);
 
     /* copy the data from user space into our urb */
-    copy_from_user(skel->write_urb->transfer_buffer, buffer, bytes_written);
+    copy_from_user(buf, user_buffer, writesize);
 
     /* set up our urb */
-    usb_fill_bulk_urb(skel->write_urb,
-		      skel->dev,
-		      usb_sndbulkpipe(skel->dev, skel->bulk_out_endpointAddr),
-		      skel->write_urb->transfer_buffer,
-		      bytes_written,
+    usb_fill_bulk_urb(urb,
+		      dev->udev,
+		      usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr),
+		      buf,
+		      writesize,
 		      skel_write_bulk_callback,
-		      skel);
+		      dev);
 
     /* send the data out the bulk port */
-    result = usb_submit_urb(skel->write_urb);
-    if (result) {
-	    err("Failed submitting write urb, error %d", result);
+    retval = usb_submit_urb(urb, GFP_KERNEL);
+    if (retval) {
+	    dev_err(&dev->interface->dev,
+                "%s - failed submitting write urb, error %d\n",
+                __func__, retval);
     }
 
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] Docs: usb: update err() to pr_err() and replace __FILE__
  2021-10-29 19:39 ` [PATCH 1/3] Docs: usb: update err() to pr_err() and replace __FILE__ Philipp Hortmann
@ 2021-10-29 20:33   ` Sergey Shtylyov
  2021-10-30  9:32     ` Sergey Shtylyov
  0 siblings, 1 reply; 6+ messages in thread
From: Sergey Shtylyov @ 2021-10-29 20:33 UTC (permalink / raw)
  To: Philipp Hortmann, corbet, linux-doc, linux-kernel; +Cc: linux-usb

On 10/29/21 10:39 PM, Philipp Hortmann wrote:

> update err() to pr_err() and replace __FILE__
> 
> Signed-off-by: Philipp Hortmann <philipp.g.hortmann@gmail.com>
> ---
>  Documentation/driver-api/usb/writing_usb_driver.rst | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/driver-api/usb/writing_usb_driver.rst b/Documentation/driver-api/usb/writing_usb_driver.rst
> index 2176297e5765..5c29e5bdbe88 100644
> --- a/Documentation/driver-api/usb/writing_usb_driver.rst
> +++ b/Documentation/driver-api/usb/writing_usb_driver.rst
> @@ -91,8 +91,8 @@ usually in the driver's init function, as shown here::
>  	    /* register this driver with the USB subsystem */
>  	    result = usb_register(&skel_driver);
>  	    if (result < 0) {
> -		    err("usb_register failed for the "__FILE__ "driver."
> -			"Error number %d", result);
> +		    pr_err("usb_register failed for the %s driver. "

   Don't break up the kernel message like this. The current code is a bad example --
high time to fix it. :-)

> +			   "Error number %d", skel_driver.name, result);
>  		    return -1;
>  	    }
>  

MBR, Sergey

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] Docs: usb: update err() to pr_err() and replace __FILE__
  2021-10-29 20:33   ` Sergey Shtylyov
@ 2021-10-30  9:32     ` Sergey Shtylyov
  0 siblings, 0 replies; 6+ messages in thread
From: Sergey Shtylyov @ 2021-10-30  9:32 UTC (permalink / raw)
  To: Philipp Hortmann, corbet, linux-doc, linux-kernel; +Cc: linux-usb

On 29.10.2021 23:33, Sergey Shtylyov wrote:

[...]
>> update err() to pr_err() and replace __FILE__
>>
>> Signed-off-by: Philipp Hortmann <philipp.g.hortmann@gmail.com>
>> ---
>>   Documentation/driver-api/usb/writing_usb_driver.rst | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/Documentation/driver-api/usb/writing_usb_driver.rst b/Documentation/driver-api/usb/writing_usb_driver.rst
>> index 2176297e5765..5c29e5bdbe88 100644
>> --- a/Documentation/driver-api/usb/writing_usb_driver.rst
>> +++ b/Documentation/driver-api/usb/writing_usb_driver.rst
>> @@ -91,8 +91,8 @@ usually in the driver's init function, as shown here::
>>   	    /* register this driver with the USB subsystem */
>>   	    result = usb_register(&skel_driver);
>>   	    if (result < 0) {
>> -		    err("usb_register failed for the "__FILE__ "driver."
>> -			"Error number %d", result);
>> +		    pr_err("usb_register failed for the %s driver. "
> 
>     Don't break up the kernel message like this. The current code is a bad example --
> high time to fix it. :-)
> 
>> +			   "Error number %d", skel_driver.name, result);

    Oh, and add `\n' at the end of message.

[...]

MBR, Sergey

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-10-30  9:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-29 19:39 [PATCH 0/3] Docs: usb: Example code updates from usb-skeleton Philipp Hortmann
2021-10-29 19:39 ` [PATCH 1/3] Docs: usb: update err() to pr_err() and replace __FILE__ Philipp Hortmann
2021-10-29 20:33   ` Sergey Shtylyov
2021-10-30  9:32     ` Sergey Shtylyov
2021-10-29 19:39 ` [PATCH 2/3] Docs: usb: update comment and code near increment usage count Philipp Hortmann
2021-10-29 19:40 ` [PATCH 3/3] Docs: usb: update writesize, copy_from_user, usb_fill_bulk_urb, usb_submit_urb Philipp Hortmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).