diff mbox series

[net,v8,2/2] net/ps3_gelic_net: Use dma_mapping_error

Message ID 642c56a7da025406c36862464f5a15aba3e5340e.1678570942.git.geoff@infradead.org (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net/ps3_gelic_net: DMA related fixes | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 18 this patch: 18
netdev/cc_maintainers fail 2 blamed authors not CCed: jeff@garzik.org mokuno@sm.sony.co.jp; 7 maintainers not CCed: christophe.leroy@csgroup.eu jeff@garzik.org mokuno@sm.sony.co.jp edumazet@google.com npiggin@gmail.com mpe@ellerman.id.au linuxppc-dev@lists.ozlabs.org
netdev/build_clang success Errors and warnings before: 18 this patch: 18
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 18 this patch: 18
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 52 lines checked
netdev/kdoc success Errors and warnings before: 5 this patch: 5
netdev/source_inline success Was 0 now: 0

Commit Message

Geoff Levand March 11, 2023, 9:46 p.m. UTC
The current Gelic Etherenet driver was checking the return value of its
dma_map_single call, and not using the dma_mapping_error() routine.

Fixes runtime problems like these:

  DMA-API: ps3_gelic_driver sb_05: device driver failed to check map error
  WARNING: CPU: 0 PID: 0 at kernel/dma/debug.c:1027 .check_unmap+0x888/0x8dc

Fixes: 02c1889166b4 ("ps3: gigabit ethernet driver for PS3, take3")
Signed-off-by: Geoff Levand <geoff@infradead.org>
---
 drivers/net/ethernet/toshiba/ps3_gelic_net.c | 24 +++++++++++---------
 1 file changed, 13 insertions(+), 11 deletions(-)

Comments

Alexander Duyck March 11, 2023, 10:41 p.m. UTC | #1
On Sat, 2023-03-11 at 21:46 +0000, Geoff Levand wrote:
> The current Gelic Etherenet driver was checking the return value of its
> dma_map_single call, and not using the dma_mapping_error() routine.
> 
> Fixes runtime problems like these:
> 
>   DMA-API: ps3_gelic_driver sb_05: device driver failed to check map error
>   WARNING: CPU: 0 PID: 0 at kernel/dma/debug.c:1027 .check_unmap+0x888/0x8dc
> 
> Fixes: 02c1889166b4 ("ps3: gigabit ethernet driver for PS3, take3")
> Signed-off-by: Geoff Levand <geoff@infradead.org>
> ---
>  drivers/net/ethernet/toshiba/ps3_gelic_net.c | 24 +++++++++++---------
>  1 file changed, 13 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> index 56557fc8d18a..87d3c768286e 100644
> --- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> +++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> @@ -325,15 +325,17 @@ static int gelic_card_init_chain(struct gelic_card *card,
>  
>  	/* set up the hardware pointers in each descriptor */
>  	for (i = 0; i < no; i++, descr++) {
> +		dma_addr_t cpu_addr;
> +
>  		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
> -		descr->bus_addr =
> -			dma_map_single(ctodev(card), descr,
> -				       GELIC_DESCR_SIZE,
> -				       DMA_BIDIRECTIONAL);
>  
> -		if (!descr->bus_addr)
> +		cpu_addr = dma_map_single(ctodev(card), descr,
> +					  GELIC_DESCR_SIZE, DMA_BIDIRECTIONAL);
> +
> +		if (dma_mapping_error(ctodev(card), cpu_addr))
>  			goto iommu_error;
>  
> +		descr->bus_addr = cpu_to_be32(cpu_addr);
>  		descr->next = descr + 1;
>  		descr->prev = descr - 1;
>  	}
> @@ -377,6 +379,7 @@ static int gelic_card_init_chain(struct gelic_card *card,
>  static int gelic_descr_prepare_rx(struct gelic_card *card,
>  				  struct gelic_descr *descr)
>  {
> +	dma_addr_t cpu_addr;
>  	int offset;
>  
>  	if (gelic_descr_get_status(descr) !=  GELIC_DESCR_DMA_NOT_IN_USE)
> @@ -398,11 +401,10 @@ static int gelic_descr_prepare_rx(struct gelic_card *card,
>  	if (offset)
>  		skb_reserve(descr->skb, GELIC_NET_RXBUF_ALIGN - offset);
>  	/* io-mmu-map the skb */
> -	descr->buf_addr = cpu_to_be32(dma_map_single(ctodev(card),
> -						     descr->skb->data,
> -						     gelic_rx_skb_size,
> -						     DMA_FROM_DEVICE));
> -	if (!descr->buf_addr) {
> +	cpu_addr = dma_map_single(ctodev(card), descr->skb->data,
> +				  gelic_rx_skb_size, DMA_FROM_DEVICE);
> +	descr->buf_addr = cpu_to_be32(cpu_addr);
> +	if (dma_mapping_error(ctodev(card), cpu_addr)) {
>  		dev_kfree_skb_any(descr->skb);
>  		descr->skb = NULL;
>  		dev_info(ctodev(card),
> @@ -782,7 +784,7 @@ static int gelic_descr_prepare_tx(struct gelic_card *card,
>  
>  	buf = dma_map_single(ctodev(card), skb->data, skb->len, DMA_TO_DEVICE);
>  
> -	if (!buf) {
> +	if (dma_mapping_error(ctodev(card), buf)) {
>  		dev_err(ctodev(card),
>  			"dma map 2 failed (%p, %i). Dropping packet\n",
>  			skb->data, skb->len);

Looks good to me. The only tweak I would make is maybe using "dma_addr"
, "phys_addr" or "bus_addr" instead of "cpu_addr", however that is more
cosmetic than anything else.

Reviewed-by: Alexander Duyck <alexanderduyck@fb.com>
Geoff Levand March 18, 2023, 5:37 p.m. UTC | #2
On 3/11/23 14:41, Alexander H Duyck wrote:
> On Sat, 2023-03-11 at 21:46 +0000, Geoff Levand wrote:
>> The current Gelic Etherenet driver was checking the return value of its
>> dma_map_single call, and not using the dma_mapping_error() routine.
>>
>> Fixes runtime problems like these:
>>
>>   DMA-API: ps3_gelic_driver sb_05: device driver failed to check map error
>>   WARNING: CPU: 0 PID: 0 at kernel/dma/debug.c:1027 .check_unmap+0x888/0x8dc
>>
>> Fixes: 02c1889166b4 ("ps3: gigabit ethernet driver for PS3, take3")
>> Signed-off-by: Geoff Levand <geoff@infradead.org>
>> ---
>>  drivers/net/ethernet/toshiba/ps3_gelic_net.c | 24 +++++++++++---------
>>  1 file changed, 13 insertions(+), 11 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
>> index 56557fc8d18a..87d3c768286e 100644
>> --- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
>> +++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
>> @@ -325,15 +325,17 @@ static int gelic_card_init_chain(struct gelic_card *card,
>>  
>>  	/* set up the hardware pointers in each descriptor */
>>  	for (i = 0; i < no; i++, descr++) {
>> +		dma_addr_t cpu_addr;
>> +
>>  		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
>> -		descr->bus_addr =
>> -			dma_map_single(ctodev(card), descr,
>> -				       GELIC_DESCR_SIZE,
>> -				       DMA_BIDIRECTIONAL);
>>  
>> -		if (!descr->bus_addr)
>> +		cpu_addr = dma_map_single(ctodev(card), descr,
>> +					  GELIC_DESCR_SIZE, DMA_BIDIRECTIONAL);
>> +
>> +		if (dma_mapping_error(ctodev(card), cpu_addr))
>>  			goto iommu_error;
>>  
>> +		descr->bus_addr = cpu_to_be32(cpu_addr);
>>  		descr->next = descr + 1;
>>  		descr->prev = descr - 1;
>>  	}
>> @@ -377,6 +379,7 @@ static int gelic_card_init_chain(struct gelic_card *card,
>>  static int gelic_descr_prepare_rx(struct gelic_card *card,
>>  				  struct gelic_descr *descr)
>>  {
>> +	dma_addr_t cpu_addr;
>>  	int offset;
>>  
>>  	if (gelic_descr_get_status(descr) !=  GELIC_DESCR_DMA_NOT_IN_USE)
>> @@ -398,11 +401,10 @@ static int gelic_descr_prepare_rx(struct gelic_card *card,
>>  	if (offset)
>>  		skb_reserve(descr->skb, GELIC_NET_RXBUF_ALIGN - offset);
>>  	/* io-mmu-map the skb */
>> -	descr->buf_addr = cpu_to_be32(dma_map_single(ctodev(card),
>> -						     descr->skb->data,
>> -						     gelic_rx_skb_size,
>> -						     DMA_FROM_DEVICE));
>> -	if (!descr->buf_addr) {
>> +	cpu_addr = dma_map_single(ctodev(card), descr->skb->data,
>> +				  gelic_rx_skb_size, DMA_FROM_DEVICE);
>> +	descr->buf_addr = cpu_to_be32(cpu_addr);
>> +	if (dma_mapping_error(ctodev(card), cpu_addr)) {
>>  		dev_kfree_skb_any(descr->skb);
>>  		descr->skb = NULL;
>>  		dev_info(ctodev(card),
>> @@ -782,7 +784,7 @@ static int gelic_descr_prepare_tx(struct gelic_card *card,
>>  
>>  	buf = dma_map_single(ctodev(card), skb->data, skb->len, DMA_TO_DEVICE);
>>  
>> -	if (!buf) {
>> +	if (dma_mapping_error(ctodev(card), buf)) {
>>  		dev_err(ctodev(card),
>>  			"dma map 2 failed (%p, %i). Dropping packet\n",
>>  			skb->data, skb->len);
> 
> Looks good to me. The only tweak I would make is maybe using "dma_addr"
> , "phys_addr" or "bus_addr" instead of "cpu_addr", however that is more
> cosmetic than anything else.

Well, cpu_addr is used for cpu_to_be32(cpu_addr)...

> Reviewed-by: Alexander Duyck <alexanderduyck@fb.com>

Thanks for the review.

-Geoff
diff mbox series

Patch

diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
index 56557fc8d18a..87d3c768286e 100644
--- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
+++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
@@ -325,15 +325,17 @@  static int gelic_card_init_chain(struct gelic_card *card,
 
 	/* set up the hardware pointers in each descriptor */
 	for (i = 0; i < no; i++, descr++) {
+		dma_addr_t cpu_addr;
+
 		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
-		descr->bus_addr =
-			dma_map_single(ctodev(card), descr,
-				       GELIC_DESCR_SIZE,
-				       DMA_BIDIRECTIONAL);
 
-		if (!descr->bus_addr)
+		cpu_addr = dma_map_single(ctodev(card), descr,
+					  GELIC_DESCR_SIZE, DMA_BIDIRECTIONAL);
+
+		if (dma_mapping_error(ctodev(card), cpu_addr))
 			goto iommu_error;
 
+		descr->bus_addr = cpu_to_be32(cpu_addr);
 		descr->next = descr + 1;
 		descr->prev = descr - 1;
 	}
@@ -377,6 +379,7 @@  static int gelic_card_init_chain(struct gelic_card *card,
 static int gelic_descr_prepare_rx(struct gelic_card *card,
 				  struct gelic_descr *descr)
 {
+	dma_addr_t cpu_addr;
 	int offset;
 
 	if (gelic_descr_get_status(descr) !=  GELIC_DESCR_DMA_NOT_IN_USE)
@@ -398,11 +401,10 @@  static int gelic_descr_prepare_rx(struct gelic_card *card,
 	if (offset)
 		skb_reserve(descr->skb, GELIC_NET_RXBUF_ALIGN - offset);
 	/* io-mmu-map the skb */
-	descr->buf_addr = cpu_to_be32(dma_map_single(ctodev(card),
-						     descr->skb->data,
-						     gelic_rx_skb_size,
-						     DMA_FROM_DEVICE));
-	if (!descr->buf_addr) {
+	cpu_addr = dma_map_single(ctodev(card), descr->skb->data,
+				  gelic_rx_skb_size, DMA_FROM_DEVICE);
+	descr->buf_addr = cpu_to_be32(cpu_addr);
+	if (dma_mapping_error(ctodev(card), cpu_addr)) {
 		dev_kfree_skb_any(descr->skb);
 		descr->skb = NULL;
 		dev_info(ctodev(card),
@@ -782,7 +784,7 @@  static int gelic_descr_prepare_tx(struct gelic_card *card,
 
 	buf = dma_map_single(ctodev(card), skb->data, skb->len, DMA_TO_DEVICE);
 
-	if (!buf) {
+	if (dma_mapping_error(ctodev(card), buf)) {
 		dev_err(ctodev(card),
 			"dma map 2 failed (%p, %i). Dropping packet\n",
 			skb->data, skb->len);