Skip to content

Commit cc59f3b

Browse files
bvanasschemartinkpetersen
authored andcommitted
scsi: ufs: core: Improve return value documentation
Some functions return a negative value to indicate an error while other functions return a value != 0 to indicate an error. Document the return value behavior where this documentation is missing and fix the return value documentation where necessary. Add warnings to detect mismatches between documentation and implementation. This matters because several sysfs callback functions only work correctly if a negative value is returned upon error. Signed-off-by: Bart Van Assche <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 26b971d commit cc59f3b

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

drivers/ufs/core/ufshcd.c

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,7 +2566,7 @@ ufshcd_wait_for_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd)
25662566
* @hba: per adapter instance
25672567
* @uic_cmd: UIC command
25682568
*
2569-
* Return: 0 only if success.
2569+
* Return: 0 if successful; < 0 upon failure.
25702570
*/
25712571
static int
25722572
__ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd)
@@ -3072,6 +3072,9 @@ static void ufshcd_setup_dev_cmd(struct ufs_hba *hba, struct ufshcd_lrb *lrbp,
30723072
hba->dev_cmd.type = cmd_type;
30733073
}
30743074

3075+
/*
3076+
* Return: 0 upon success; < 0 upon failure.
3077+
*/
30753078
static int ufshcd_compose_dev_cmd(struct ufs_hba *hba,
30763079
struct ufshcd_lrb *lrbp, enum dev_cmd_type cmd_type, int tag)
30773080
{
@@ -3184,9 +3187,13 @@ ufshcd_dev_cmd_completion(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)
31843187
break;
31853188
}
31863189

3190+
WARN_ONCE(err > 0, "Incorrect return value %d > 0\n", err);
31873191
return err;
31883192
}
31893193

3194+
/*
3195+
* Return: 0 upon success; < 0 upon failure.
3196+
*/
31903197
static int ufshcd_wait_for_dev_cmd(struct ufs_hba *hba,
31913198
struct ufshcd_lrb *lrbp, int max_timeout)
31923199
{
@@ -3261,6 +3268,7 @@ static int ufshcd_wait_for_dev_cmd(struct ufs_hba *hba,
32613268
}
32623269
}
32633270

3271+
WARN_ONCE(err > 0, "Incorrect return value %d > 0\n", err);
32643272
return err;
32653273
}
32663274

@@ -3278,6 +3286,9 @@ static void ufshcd_dev_man_unlock(struct ufs_hba *hba)
32783286
ufshcd_release(hba);
32793287
}
32803288

3289+
/*
3290+
* Return: 0 upon success; < 0 upon failure.
3291+
*/
32813292
static int ufshcd_issue_dev_cmd(struct ufs_hba *hba, struct ufshcd_lrb *lrbp,
32823293
const u32 tag, int timeout)
32833294
{
@@ -3365,6 +3376,7 @@ static int ufshcd_query_flag_retry(struct ufs_hba *hba,
33653376
dev_err(hba->dev,
33663377
"%s: query flag, opcode %d, idn %d, failed with error %d after %d retries\n",
33673378
__func__, opcode, idn, ret, retries);
3379+
WARN_ONCE(ret > 0, "Incorrect return value %d > 0\n", ret);
33683380
return ret;
33693381
}
33703382

@@ -3376,7 +3388,7 @@ static int ufshcd_query_flag_retry(struct ufs_hba *hba,
33763388
* @index: flag index to access
33773389
* @flag_res: the flag value after the query request completes
33783390
*
3379-
* Return: 0 for success, non-zero in case of failure.
3391+
* Return: 0 for success; < 0 upon failure.
33803392
*/
33813393
int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode,
33823394
enum flag_idn idn, u8 index, bool *flag_res)
@@ -3432,6 +3444,7 @@ int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode,
34323444

34333445
out_unlock:
34343446
ufshcd_dev_man_unlock(hba);
3447+
WARN_ONCE(err > 0, "Incorrect return value %d > 0\n", err);
34353448
return err;
34363449
}
34373450

@@ -3444,7 +3457,7 @@ int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode,
34443457
* @selector: selector field
34453458
* @attr_val: the attribute value after the query request completes
34463459
*
3447-
* Return: 0 for success, non-zero in case of failure.
3460+
* Return: 0 upon success; < 0 upon failure.
34483461
*/
34493462
int ufshcd_query_attr(struct ufs_hba *hba, enum query_opcode opcode,
34503463
enum attr_idn idn, u8 index, u8 selector, u32 *attr_val)
@@ -3493,6 +3506,7 @@ int ufshcd_query_attr(struct ufs_hba *hba, enum query_opcode opcode,
34933506

34943507
out_unlock:
34953508
ufshcd_dev_man_unlock(hba);
3509+
WARN_ONCE(err > 0, "Incorrect return value %d > 0\n", err);
34963510
return err;
34973511
}
34983512

@@ -3507,7 +3521,7 @@ int ufshcd_query_attr(struct ufs_hba *hba, enum query_opcode opcode,
35073521
* @attr_val: the attribute value after the query request
35083522
* completes
35093523
*
3510-
* Return: 0 for success, non-zero in case of failure.
3524+
* Return: 0 for success; < 0 upon failure.
35113525
*/
35123526
int ufshcd_query_attr_retry(struct ufs_hba *hba,
35133527
enum query_opcode opcode, enum attr_idn idn, u8 index, u8 selector,
@@ -3530,9 +3544,13 @@ int ufshcd_query_attr_retry(struct ufs_hba *hba,
35303544
dev_err(hba->dev,
35313545
"%s: query attribute, idn %d, failed with error %d after %d retries\n",
35323546
__func__, idn, ret, QUERY_REQ_RETRIES);
3547+
WARN_ONCE(ret > 0, "Incorrect return value %d > 0\n", ret);
35333548
return ret;
35343549
}
35353550

3551+
/*
3552+
* Return: 0 if successful; < 0 upon failure.
3553+
*/
35363554
static int __ufshcd_query_descriptor(struct ufs_hba *hba,
35373555
enum query_opcode opcode, enum desc_idn idn, u8 index,
35383556
u8 selector, u8 *desc_buf, int *buf_len)
@@ -3590,6 +3608,7 @@ static int __ufshcd_query_descriptor(struct ufs_hba *hba,
35903608
out_unlock:
35913609
hba->dev_cmd.query.descriptor = NULL;
35923610
ufshcd_dev_man_unlock(hba);
3611+
WARN_ONCE(err > 0, "Incorrect return value %d > 0\n", err);
35933612
return err;
35943613
}
35953614

@@ -3606,7 +3625,7 @@ static int __ufshcd_query_descriptor(struct ufs_hba *hba,
36063625
* The buf_len parameter will contain, on return, the length parameter
36073626
* received on the response.
36083627
*
3609-
* Return: 0 for success, non-zero in case of failure.
3628+
* Return: 0 for success; < 0 upon failure.
36103629
*/
36113630
int ufshcd_query_descriptor_retry(struct ufs_hba *hba,
36123631
enum query_opcode opcode,
@@ -3624,6 +3643,7 @@ int ufshcd_query_descriptor_retry(struct ufs_hba *hba,
36243643
break;
36253644
}
36263645

3646+
WARN_ONCE(err > 0, "Incorrect return value %d > 0\n", err);
36273647
return err;
36283648
}
36293649

@@ -3636,7 +3656,7 @@ int ufshcd_query_descriptor_retry(struct ufs_hba *hba,
36363656
* @param_read_buf: pointer to buffer where parameter would be read
36373657
* @param_size: sizeof(param_read_buf)
36383658
*
3639-
* Return: 0 in case of success, non-zero otherwise.
3659+
* Return: 0 in case of success; < 0 upon failure.
36403660
*/
36413661
int ufshcd_read_desc_param(struct ufs_hba *hba,
36423662
enum desc_idn desc_id,
@@ -3703,6 +3723,7 @@ int ufshcd_read_desc_param(struct ufs_hba *hba,
37033723
out:
37043724
if (is_kmalloc)
37053725
kfree(desc_buf);
3726+
WARN_ONCE(ret > 0, "Incorrect return value %d > 0\n", ret);
37063727
return ret;
37073728
}
37083729

@@ -3816,7 +3837,7 @@ int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index,
38163837
* @param_read_buf: pointer to buffer where parameter would be read
38173838
* @param_size: sizeof(param_read_buf)
38183839
*
3819-
* Return: 0 in case of success, non-zero otherwise.
3840+
* Return: 0 in case of success; < 0 upon failure.
38203841
*/
38213842
static inline int ufshcd_read_unit_desc_param(struct ufs_hba *hba,
38223843
int lun,
@@ -4794,7 +4815,7 @@ static int ufshcd_complete_dev_init(struct ufs_hba *hba)
47944815
* 3. Program UTRL and UTMRL base address
47954816
* 4. Configure run-stop-registers
47964817
*
4797-
* Return: 0 on success, non-zero value on failure.
4818+
* Return: 0 if successful; < 0 upon failure.
47984819
*/
47994820
int ufshcd_make_hba_operational(struct ufs_hba *hba)
48004821
{

0 commit comments

Comments
 (0)