* [PATCH] wan-cosa: Use memdup_user() rather than duplicating its implementation
@ 2016-08-20 8:25 ` SF Markus Elfring
0 siblings, 0 replies; 11+ messages in thread
From: SF Markus Elfring @ 2016-08-20 8:25 UTC (permalink / raw)
To: netdev, Jan Kasprzak; +Cc: LKML, kernel-janitors, Julia Lawall, Nicolas Palix
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 20 Aug 2016 10:10:12 +0200
Reuse existing functionality from memdup_user() instead of keeping
duplicate source code.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/net/wan/cosa.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/drivers/net/wan/cosa.c b/drivers/net/wan/cosa.c
index b87fe0a..02f5809 100644
--- a/drivers/net/wan/cosa.c
+++ b/drivers/net/wan/cosa.c
@@ -875,16 +875,10 @@ static ssize_t cosa_write(struct file *file,
if (count > COSA_MTU)
count = COSA_MTU;
- /* Allocate the buffer */
- kbuf = kmalloc(count, GFP_KERNEL|GFP_DMA);
- if (kbuf == NULL) {
+ kbuf = memdup_user(buf, count);
+ if (IS_ERR(kbuf)) {
up(&chan->wsem);
- return -ENOMEM;
- }
- if (copy_from_user(kbuf, buf, count)) {
- up(&chan->wsem);
- kfree(kbuf);
- return -EFAULT;
+ return PTR_ERR(kbuf);
}
chan->tx_status=0;
cosa_start_tx(chan, kbuf, count);
--
2.9.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH] wan-cosa: Use memdup_user() rather than duplicating its implementation
@ 2016-08-20 8:25 ` SF Markus Elfring
0 siblings, 0 replies; 11+ messages in thread
From: SF Markus Elfring @ 2016-08-20 8:25 UTC (permalink / raw)
To: netdev, Jan Kasprzak; +Cc: LKML, kernel-janitors, Julia Lawall, Nicolas Palix
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 20 Aug 2016 10:10:12 +0200
Reuse existing functionality from memdup_user() instead of keeping
duplicate source code.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/net/wan/cosa.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/drivers/net/wan/cosa.c b/drivers/net/wan/cosa.c
index b87fe0a..02f5809 100644
--- a/drivers/net/wan/cosa.c
+++ b/drivers/net/wan/cosa.c
@@ -875,16 +875,10 @@ static ssize_t cosa_write(struct file *file,
if (count > COSA_MTU)
count = COSA_MTU;
- /* Allocate the buffer */
- kbuf = kmalloc(count, GFP_KERNEL|GFP_DMA);
- if (kbuf = NULL) {
+ kbuf = memdup_user(buf, count);
+ if (IS_ERR(kbuf)) {
up(&chan->wsem);
- return -ENOMEM;
- }
- if (copy_from_user(kbuf, buf, count)) {
- up(&chan->wsem);
- kfree(kbuf);
- return -EFAULT;
+ return PTR_ERR(kbuf);
}
chan->tx_status=0;
cosa_start_tx(chan, kbuf, count);
--
2.9.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH] wan-cosa: Use memdup_user() rather than duplicating its implementation
2016-08-20 8:25 ` SF Markus Elfring
(?)
@ 2016-08-20 8:42 ` Christophe JAILLET
2016-08-21 2:12 ` David Miller
-1 siblings, 1 reply; 11+ messages in thread
From: Christophe JAILLET @ 2016-08-20 8:42 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, kernel-janitors
Le 20/08/2016 à 10:25, SF Markus Elfring a écrit :
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 20 Aug 2016 10:10:12 +0200
>
> Reuse existing functionality from memdup_user() instead of keeping
> duplicate source code.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> drivers/net/wan/cosa.c | 12 +++---------
> 1 file changed, 3 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/net/wan/cosa.c b/drivers/net/wan/cosa.c
> index b87fe0a..02f5809 100644
> --- a/drivers/net/wan/cosa.c
> +++ b/drivers/net/wan/cosa.c
> @@ -875,16 +875,10 @@ static ssize_t cosa_write(struct file *file,
> if (count > COSA_MTU)
> count = COSA_MTU;
>
> - /* Allocate the buffer */
> - kbuf = kmalloc(count, GFP_KERNEL|GFP_DMA);
In this case, 'memdup_user()' has a different meaning, as GFP_DMA will
no more be used for this memory allocation.
> - if (kbuf == NULL) {
> + kbuf = memdup_user(buf, count);
> + if (IS_ERR(kbuf)) {
> up(&chan->wsem);
> - return -ENOMEM;
> - }
> - if (copy_from_user(kbuf, buf, count)) {
> - up(&chan->wsem);
> - kfree(kbuf);
> - return -EFAULT;
> + return PTR_ERR(kbuf);
> }
> chan->tx_status=0;
> cosa_start_tx(chan, kbuf, count);
---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
https://www.avast.com/antivirus
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] wan-cosa: Use memdup_user() rather than duplicating its implementation
2016-08-20 8:42 ` Christophe JAILLET
@ 2016-08-21 2:12 ` David Miller
0 siblings, 0 replies; 11+ messages in thread
From: David Miller @ 2016-08-21 2:12 UTC (permalink / raw)
To: christophe.jaillet; +Cc: netdev, linux-kernel, kernel-janitors
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Date: Sat, 20 Aug 2016 10:42:54 +0200
> Le 20/08/2016 à 10:25, SF Markus Elfring a écrit :
>> @@ -875,16 +875,10 @@ static ssize_t cosa_write(struct file *file,
>> if (count > COSA_MTU)
>> count = COSA_MTU;
>>
>> - /* Allocate the buffer */
>> - kbuf = kmalloc(count, GFP_KERNEL|GFP_DMA);
> In this case, 'memdup_user()' has a different meaning, as GFP_DMA will
> no more be used for this memory allocation.
Agreed, this transformation is not equivalent.
Markus, please do not make these changes so blindly.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] wan-cosa: Use memdup_user() rather than duplicating its implementation
@ 2016-08-21 2:12 ` David Miller
0 siblings, 0 replies; 11+ messages in thread
From: David Miller @ 2016-08-21 2:12 UTC (permalink / raw)
To: christophe.jaillet; +Cc: netdev, linux-kernel, kernel-janitors
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Date: Sat, 20 Aug 2016 10:42:54 +0200
> Le 20/08/2016 à 10:25, SF Markus Elfring a écrit :
>> @@ -875,16 +875,10 @@ static ssize_t cosa_write(struct file *file,
>> if (count > COSA_MTU)
>> count = COSA_MTU;
>>
>> - /* Allocate the buffer */
>> - kbuf = kmalloc(count, GFP_KERNEL|GFP_DMA);
> In this case, 'memdup_user()' has a different meaning, as GFP_DMA will
> no more be used for this memory allocation.
Agreed, this transformation is not equivalent.
Markus, please do not make these changes so blindly.
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] wan-cosa: Use memdup_user() rather than duplicating its implementation
2016-08-20 8:25 ` SF Markus Elfring
@ 2016-08-24 15:21 ` Jan Kasprzak
-1 siblings, 0 replies; 11+ messages in thread
From: Jan Kasprzak @ 2016-08-24 15:21 UTC (permalink / raw)
To: SF Markus Elfring
Cc: netdev, LKML, kernel-janitors, Julia Lawall, Nicolas Palix
Hello,
SF Markus Elfring wrote:
: From: Markus Elfring <elfring@users.sourceforge.net>
: Date: Sat, 20 Aug 2016 10:10:12 +0200
:
: Reuse existing functionality from memdup_user() instead of keeping
: duplicate source code.
:
: This issue was detected by using the Coccinelle software.
What about the GFP_DMA attribute, which your patch deletes?
The buffer in question has to be ISA DMA-able.
Anyway, COSA is an ancient ISA device, which is out of production
for at least 10 years. I don't have a box with ISA bus anymore, so I can't
even test the modifications of the wan/cosa.c (I do have a COSA board
itself, though :-).
I suggest keeping the driver intact if possible, in case somebody
still uses it.
Sincerely,
-Yenya
: Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
: ---
: drivers/net/wan/cosa.c | 12 +++---------
: 1 file changed, 3 insertions(+), 9 deletions(-)
:
: diff --git a/drivers/net/wan/cosa.c b/drivers/net/wan/cosa.c
: index b87fe0a..02f5809 100644
: --- a/drivers/net/wan/cosa.c
: +++ b/drivers/net/wan/cosa.c
: @@ -875,16 +875,10 @@ static ssize_t cosa_write(struct file *file,
: if (count > COSA_MTU)
: count = COSA_MTU;
:
: - /* Allocate the buffer */
: - kbuf = kmalloc(count, GFP_KERNEL|GFP_DMA);
: - if (kbuf == NULL) {
: + kbuf = memdup_user(buf, count);
: + if (IS_ERR(kbuf)) {
: up(&chan->wsem);
: - return -ENOMEM;
: - }
: - if (copy_from_user(kbuf, buf, count)) {
: - up(&chan->wsem);
: - kfree(kbuf);
: - return -EFAULT;
: + return PTR_ERR(kbuf);
: }
: chan->tx_status=0;
: cosa_start_tx(chan, kbuf, count);
: --
: 2.9.3
--
| Jan "Yenya" Kasprzak <kas at {fi.muni.cz - work | yenya.net - private}> |
| http://www.fi.muni.cz/~kas/ GPG: 4096R/A45477D5 |
Like most things in Windows, on the surface it looks great.
-- Jeremy Allison, A Tale of Two Standards
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] wan-cosa: Use memdup_user() rather than duplicating its implementation
@ 2016-08-24 15:21 ` Jan Kasprzak
0 siblings, 0 replies; 11+ messages in thread
From: Jan Kasprzak @ 2016-08-24 15:21 UTC (permalink / raw)
To: SF Markus Elfring
Cc: netdev, LKML, kernel-janitors, Julia Lawall, Nicolas Palix
Hello,
SF Markus Elfring wrote:
: From: Markus Elfring <elfring@users.sourceforge.net>
: Date: Sat, 20 Aug 2016 10:10:12 +0200
:
: Reuse existing functionality from memdup_user() instead of keeping
: duplicate source code.
:
: This issue was detected by using the Coccinelle software.
What about the GFP_DMA attribute, which your patch deletes?
The buffer in question has to be ISA DMA-able.
Anyway, COSA is an ancient ISA device, which is out of production
for at least 10 years. I don't have a box with ISA bus anymore, so I can't
even test the modifications of the wan/cosa.c (I do have a COSA board
itself, though :-).
I suggest keeping the driver intact if possible, in case somebody
still uses it.
Sincerely,
-Yenya
: Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
: ---
: drivers/net/wan/cosa.c | 12 +++---------
: 1 file changed, 3 insertions(+), 9 deletions(-)
:
: diff --git a/drivers/net/wan/cosa.c b/drivers/net/wan/cosa.c
: index b87fe0a..02f5809 100644
: --- a/drivers/net/wan/cosa.c
: +++ b/drivers/net/wan/cosa.c
: @@ -875,16 +875,10 @@ static ssize_t cosa_write(struct file *file,
: if (count > COSA_MTU)
: count = COSA_MTU;
:
: - /* Allocate the buffer */
: - kbuf = kmalloc(count, GFP_KERNEL|GFP_DMA);
: - if (kbuf = NULL) {
: + kbuf = memdup_user(buf, count);
: + if (IS_ERR(kbuf)) {
: up(&chan->wsem);
: - return -ENOMEM;
: - }
: - if (copy_from_user(kbuf, buf, count)) {
: - up(&chan->wsem);
: - kfree(kbuf);
: - return -EFAULT;
: + return PTR_ERR(kbuf);
: }
: chan->tx_status=0;
: cosa_start_tx(chan, kbuf, count);
: --
: 2.9.3
--
| Jan "Yenya" Kasprzak <kas at {fi.muni.cz - work | yenya.net - private}> |
| http://www.fi.muni.cz/~kas/ GPG: 4096R/A45477D5 |
Like most things in Windows, on the surface it looks great.
-- Jeremy Allison, A Tale of Two Standards
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: wan-cosa: Use memdup_user() rather than duplicating its implementation
2016-08-24 15:21 ` Jan Kasprzak
@ 2016-08-24 16:14 ` SF Markus Elfring
-1 siblings, 0 replies; 11+ messages in thread
From: SF Markus Elfring @ 2016-08-24 16:14 UTC (permalink / raw)
To: Jan Kasprzak; +Cc: netdev, LKML, kernel-janitors, Julia Lawall, Nicolas Palix
> What about the GFP_DMA attribute, which your patch deletes?
> The buffer in question has to be ISA DMA-able.
Thanks for your constructive feedback.
Would you be interested in using a variant of the function "memdup_…"
with which the corresponding memory allocation option can be preserved?
Regards,
Markus
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: wan-cosa: Use memdup_user() rather than duplicating its implementation
@ 2016-08-24 16:14 ` SF Markus Elfring
0 siblings, 0 replies; 11+ messages in thread
From: SF Markus Elfring @ 2016-08-24 16:14 UTC (permalink / raw)
To: Jan Kasprzak; +Cc: netdev, LKML, kernel-janitors, Julia Lawall, Nicolas Palix
> What about the GFP_DMA attribute, which your patch deletes?
> The buffer in question has to be ISA DMA-able.
Thanks for your constructive feedback.
Would you be interested in using a variant of the function "memdup_…"
with which the corresponding memory allocation option can be preserved?
Regards,
Markus
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: wan-cosa: Use memdup_user() rather than duplicating its implementation
2016-08-24 16:14 ` SF Markus Elfring
@ 2016-08-25 9:13 ` Jan Kasprzak
-1 siblings, 0 replies; 11+ messages in thread
From: Jan Kasprzak @ 2016-08-25 9:13 UTC (permalink / raw)
To: SF Markus Elfring
Cc: netdev, LKML, kernel-janitors, Julia Lawall, Nicolas Palix
SF Markus Elfring wrote:
: > What about the GFP_DMA attribute, which your patch deletes?
: > The buffer in question has to be ISA DMA-able.
:
: Thanks for your constructive feedback.
:
: Would you be interested in using a variant of the function "memdup_…"
: with which the corresponding memory allocation option can be preserved?
I am not sure that extending an in-kernel API just for one
legacy driver is what we want. As I said, I would prefer the driver
unchanged, if possible.
Maybe it is the time for gradually phasing out ISA DMA support and
all the legacy drivers which use it?
Sincerely,
-Yenya
--
| Jan "Yenya" Kasprzak <kas at {fi.muni.cz - work | yenya.net - private}> |
| http://www.fi.muni.cz/~kas/ GPG: 4096R/A45477D5 |
Like most things in Windows, on the surface it looks great.
-- Jeremy Allison, A Tale of Two Standards
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: wan-cosa: Use memdup_user() rather than duplicating its implementation
@ 2016-08-25 9:13 ` Jan Kasprzak
0 siblings, 0 replies; 11+ messages in thread
From: Jan Kasprzak @ 2016-08-25 9:13 UTC (permalink / raw)
To: SF Markus Elfring
Cc: netdev, LKML, kernel-janitors, Julia Lawall, Nicolas Palix
SF Markus Elfring wrote:
: > What about the GFP_DMA attribute, which your patch deletes?
: > The buffer in question has to be ISA DMA-able.
:
: Thanks for your constructive feedback.
:
: Would you be interested in using a variant of the function "memdup_…"
: with which the corresponding memory allocation option can be preserved?
I am not sure that extending an in-kernel API just for one
legacy driver is what we want. As I said, I would prefer the driver
unchanged, if possible.
Maybe it is the time for gradually phasing out ISA DMA support and
all the legacy drivers which use it?
Sincerely,
-Yenya
--
| Jan "Yenya" Kasprzak <kas at {fi.muni.cz - work | yenya.net - private}> |
| http://www.fi.muni.cz/~kas/ GPG: 4096R/A45477D5 |
Like most things in Windows, on the surface it looks great.
-- Jeremy Allison, A Tale of Two Standards
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2016-08-25 9:14 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-20 8:25 [PATCH] wan-cosa: Use memdup_user() rather than duplicating its implementation SF Markus Elfring
2016-08-20 8:25 ` SF Markus Elfring
2016-08-20 8:42 ` Christophe JAILLET
2016-08-21 2:12 ` David Miller
2016-08-21 2:12 ` David Miller
2016-08-24 15:21 ` Jan Kasprzak
2016-08-24 15:21 ` Jan Kasprzak
2016-08-24 16:14 ` SF Markus Elfring
2016-08-24 16:14 ` SF Markus Elfring
2016-08-25 9:13 ` Jan Kasprzak
2016-08-25 9:13 ` Jan Kasprzak
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.