Skip to contentSkip to conversation

SCSI-UFSHCD: Fine-tuning for two function implementations

PATCH In review SF Markus Elfring 3 participants 13 messages Apr 25, 2017 – Aug 26, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover SCSI-UFSHCD: Fine-tuning for two function implementations

From: Markus Elfring <[email protected]>
Date: Tue, 25 Apr 2017 22:20:02 +0200

Three update suggestions were taken into account
from static source code analysis.

Markus Elfring (3):
Use devm_kcalloc() in ufshcd_memory_alloc()
Delete an error message for a failed memory allocation in ufshcd_memory_alloc() Delete an unnecessary return statement in ufshcd_exception_event_handler()

 drivers/scsi/ufs/ufshcd.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
Signature · 1 line
2.12.2
#1 lore raw

PATCH 1/3 scsi: ufs: Use devm_kcalloc() in ufshcd_memory_alloc()

From: Markus Elfring <[email protected]>
Date: Tue, 25 Apr 2017 21:45:25 +0200

* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "devm_kcalloc".

* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 drivers/scsi/ufs/ufshcd.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/ufs/ufshcd.c +1 -2
index 9ef8ce7f01a2..ce385911a20e 100644
@@ -3270,8 +3270,7 @@ static int ufshcd_memory_alloc(struct ufs_hba *hba)
 	}
 
 	/* Allocate memory for local reference block */
-	hba->lrb = devm_kzalloc(hba->dev,
-				hba->nutrs * sizeof(struct ufshcd_lrb),
+	hba->lrb = devm_kcalloc(hba->dev, hba->nutrs, sizeof(*hba->lrb),
 				GFP_KERNEL);
 	if (!hba->lrb) {
 		dev_err(hba->dev, "LRB Memory allocation failed\n");
Signature · 1 line
2.12.2
#3 lore raw

PATCH 2/3 scsi: ufs: Delete an error message for a failed memory allocation in ufshcd_memory_alloc()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 25 Apr 2017 21:50:43 +0200

The script "checkpatch.pl" pointed information out like the following.

WARNING: Possible unnecessary 'out of memory' message

Thus remove such a statement here.

---
 drivers/scsi/ufs/ufshcd.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/scsi/ufs/ufshcd.c +2 -3
index ce385911a20e..5216e33e61a3 100644
@@ -3274,8 +3274,7 @@ static int ufshcd_memory_alloc(struct ufs_hba *hba)
 				GFP_KERNEL);
-	if (!hba->lrb) {
-		dev_err(hba->dev, "LRB Memory allocation failed\n");
+	if (!hba->lrb)
 		goto out;
-	}
+
 	return 0;
 out:
 	return -ENOMEM;
Signature · 1 line
2.12.2
#11 lore raw

PATCH 3/3 scsi: ufs: Delete an unnecessary return statement in ufshcd_exception_event_handler()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 25 Apr 2017 22:00:05 +0200

The script "checkpatch.pl" pointed information out like the following.

WARNING: void function return statements are not generally useful

Thus remove such a statement here.

---
 drivers/scsi/ufs/ufshcd.c | 1 -
 1 file changed, 1 deletion(-)
drivers/scsi/ufs/ufshcd.c +0 -1
index 5216e33e61a3..9018f26a5667 100644
@@ -4966,7 +4966,6 @@ static void ufshcd_exception_event_handler(struct work_struct *work)
 
 out:
 	pm_runtime_put_sync(hba->dev);
-	return;
 }
 
 /* Complete requests that have door-bell cleared */
Signature · 1 line
2.12.2
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] scsi: ufs: Use devm_kcalloc() in ufshcd_memory_alloc()

In reply to SF Markus Elfring
Quoted 31 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 25 Apr 2017 21:45:25 +0200

* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "devm_kcalloc".

* Replace the specification of a data structure by a pointer dereference
to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 drivers/scsi/ufs/ufshcd.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/ufs/ufshcd.c +1 -2
index 9ef8ce7f01a2..ce385911a20e 100644
@@ -3270,8 +3270,7 @@ static int ufshcd_memory_alloc(struct ufs_hba 
 *hba)
 	}
 
 	/* Allocate memory for local reference block */
-	hba->lrb = devm_kzalloc(hba->dev,
-				hba->nutrs * sizeof(struct ufshcd_lrb),
+	hba->lrb = devm_kcalloc(hba->dev, hba->nutrs, sizeof(*hba->lrb),
 				GFP_KERNEL);
 	if (!hba->lrb) {
Quoted 1 line

dev_err(hba->dev, "LRB Memory allocation failed\n");

Looks good to me.

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
Reviewed-by on v1 2/3
#4 lore raw

Re: [PATCH 2/3] scsi: ufs: Delete an error message for a failed memory allocation in ufshcd_memory_alloc()

In reply to SF Markus Elfring
Quoted 31 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 25 Apr 2017 21:50:43 +0200

The script "checkpatch.pl" pointed information out like the following.

WARNING: Possible unnecessary 'out of memory' message

Thus remove such a statement here.

Link:
http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf

---
 drivers/scsi/ufs/ufshcd.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/scsi/ufs/ufshcd.c +2 -3
index ce385911a20e..5216e33e61a3 100644
@@ -3274,8 +3274,7 @@ static int ufshcd_memory_alloc(struct ufs_hba 
 *hba)
 				GFP_KERNEL);
-	if (!hba->lrb) {
-		dev_err(hba->dev, "LRB Memory allocation failed\n");
+	if (!hba->lrb)
 		goto out;
-	}
+
 	return 0;
 out:
Quoted 1 line

return -ENOMEM;

Looks good to me.

PS: ufshcd_memory_alloc() also does some DMA coherent memory allocation (via dmam_alloc_coherent() APIs) and tries to print out the message on allocation failure. Although i don't know "out of memory" messages will be printed out by dmam_alloc_coherent() APIs or not. If it does print it out then we might want to remove our local memory allocation failure log messages.

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
Reviewed-by on v1 3/3
#12 lore raw

Re: [PATCH 3/3] scsi: ufs: Delete an unnecessary return statement in ufshcd_exception_event_handler()

In reply to SF Markus Elfring
Quoted 26 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 25 Apr 2017 22:00:05 +0200

The script "checkpatch.pl" pointed information out like the following.

WARNING: void function return statements are not generally useful

Thus remove such a statement here.

---
 drivers/scsi/ufs/ufshcd.c | 1 -
 1 file changed, 1 deletion(-)
drivers/scsi/ufs/ufshcd.c +0 -1
index 5216e33e61a3..9018f26a5667 100644
@@ -4966,7 +4966,6 @@ static void
 ufshcd_exception_event_handler(struct work_struct *work)
 
 out:
 	pm_runtime_put_sync(hba->dev);
-	return;
 }
 
Quoted 1 line

/* Complete requests that have door-bell cleared */

Looks good to me.

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#5 lore raw

Re: scsi: ufs: Delete an error message for a failed memory allocation in ufshcd_memory_alloc()

In reply to Subhash Jadavani
Quoted 2 lines

Although i don't know "out of memory" messages will be printed out by dmam_alloc_coherent() APIs or not.

Would such information belong to the programming interface documentation?

Are there any related tags or source code annotations needed?

Regards,
Markus

#6 lore raw

Re: [PATCH 2/3] scsi: ufs: Delete an error message for a failed memory allocation in ufshcd_memory_alloc()

In reply to Subhash Jadavani
Quoted 6 lines · Subhash Jadavani

PS: ufshcd_memory_alloc() also does some DMA coherent memory allocation (via dmam_alloc_coherent() APIs) and tries to print out the message on allocation failure. Although i don't know "out of memory" messages will be printed out by dmam_alloc_coherent() APIs or not. If it does print it out then we might want to remove our local memory allocation failure log messages.

Basically most everything that has a gfp_t argument does a dump_stack() on OOM unless __GFP_NOWARN is specified by that gfp_t.

#7 lore raw

Re: Checking error messages for failed memory allocations

Quoted 2 lines

Basically most everything that has a gfp_t argument does a dump_stack() on OOM unless __GFP_NOWARN is specified by that gfp_t.

How do you think about to improve any programming interface documentation around such a function property?

Are there any special checks needed for function implementations which can pass the flag “__GFP_NOWARN”?

Regards,
Markus

#8 lore raw

Re: Checking error messages for failed memory allocations

Quoted 5 lines · SF Markus Elfring
Quoted 2 lines

Basically most everything that has a gfp_t argument does a dump_stack() on OOM unless __GFP_NOWARN is specified by that gfp_t.

How do you think about to improve any programming interface documentation around such a function property?

Feel free to submit documentation patches.

Quoted 2 lines

Are there any special checks needed for function implementations which can pass the flag “__GFP_NOWARN”?

No.

#9 lore raw

Re: Checking error messages for failed memory allocations

Quoted 1 line

Feel free to submit documentation patches.

Do involved software developers agree on the functionality for stack dumps because of out of memory situations?

Regards,
Markus

#10 lore raw

Re: scsi: ufs: Delete an error message for a failed memory allocation in ufshcd_memory_alloc()

In reply to Joe Perches
Quoted 9 lines
Quoted 6 lines

PS: ufshcd_memory_alloc() also does some DMA coherent memory allocation (via dmam_alloc_coherent() APIs) and tries to print out the message on allocation failure. Although i don't know "out of memory" messages will be printed out by dmam_alloc_coherent() APIs or not. If it does print it out then we might want to remove our local memory allocation failure log messages.

Basically most everything that has a gfp_t argument does a dump_stack() on OOM unless __GFP_NOWARN is specified by that gfp_t.

How do you think about to continue the clarification for this aspect of the involved programming interfaces?

Regards,
Markus