Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <bvanassche@acm.org>
Link: https://lore.kernel.org/r/20250623215909.4169007-1-bvanassche@acm.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Bart Van Assche and committed by
Martin K. Petersen
cc59f3b6 26b971d5

+29 -8
+29 -8
drivers/ufs/core/ufshcd.c
··· 2566 2566 * @hba: per adapter instance 2567 2567 * @uic_cmd: UIC command 2568 2568 * 2569 - * Return: 0 only if success. 2569 + * Return: 0 if successful; < 0 upon failure. 2570 2570 */ 2571 2571 static int 2572 2572 __ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd) ··· 3072 3072 hba->dev_cmd.type = cmd_type; 3073 3073 } 3074 3074 3075 + /* 3076 + * Return: 0 upon success; < 0 upon failure. 3077 + */ 3075 3078 static int ufshcd_compose_dev_cmd(struct ufs_hba *hba, 3076 3079 struct ufshcd_lrb *lrbp, enum dev_cmd_type cmd_type, int tag) 3077 3080 { ··· 3187 3184 break; 3188 3185 } 3189 3186 3187 + WARN_ONCE(err > 0, "Incorrect return value %d > 0\n", err); 3190 3188 return err; 3191 3189 } 3192 3190 3191 + /* 3192 + * Return: 0 upon success; < 0 upon failure. 3193 + */ 3193 3194 static int ufshcd_wait_for_dev_cmd(struct ufs_hba *hba, 3194 3195 struct ufshcd_lrb *lrbp, int max_timeout) 3195 3196 { ··· 3268 3261 } 3269 3262 } 3270 3263 3264 + WARN_ONCE(err > 0, "Incorrect return value %d > 0\n", err); 3271 3265 return err; 3272 3266 } 3273 3267 ··· 3286 3278 ufshcd_release(hba); 3287 3279 } 3288 3280 3281 + /* 3282 + * Return: 0 upon success; < 0 upon failure. 3283 + */ 3289 3284 static int ufshcd_issue_dev_cmd(struct ufs_hba *hba, struct ufshcd_lrb *lrbp, 3290 3285 const u32 tag, int timeout) 3291 3286 { ··· 3376 3365 dev_err(hba->dev, 3377 3366 "%s: query flag, opcode %d, idn %d, failed with error %d after %d retries\n", 3378 3367 __func__, opcode, idn, ret, retries); 3368 + WARN_ONCE(ret > 0, "Incorrect return value %d > 0\n", ret); 3379 3369 return ret; 3380 3370 } 3381 3371 ··· 3388 3376 * @index: flag index to access 3389 3377 * @flag_res: the flag value after the query request completes 3390 3378 * 3391 - * Return: 0 for success, non-zero in case of failure. 3379 + * Return: 0 for success; < 0 upon failure. 3392 3380 */ 3393 3381 int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode, 3394 3382 enum flag_idn idn, u8 index, bool *flag_res) ··· 3444 3432 3445 3433 out_unlock: 3446 3434 ufshcd_dev_man_unlock(hba); 3435 + WARN_ONCE(err > 0, "Incorrect return value %d > 0\n", err); 3447 3436 return err; 3448 3437 } 3449 3438 ··· 3457 3444 * @selector: selector field 3458 3445 * @attr_val: the attribute value after the query request completes 3459 3446 * 3460 - * Return: 0 for success, non-zero in case of failure. 3447 + * Return: 0 upon success; < 0 upon failure. 3461 3448 */ 3462 3449 int ufshcd_query_attr(struct ufs_hba *hba, enum query_opcode opcode, 3463 3450 enum attr_idn idn, u8 index, u8 selector, u32 *attr_val) ··· 3506 3493 3507 3494 out_unlock: 3508 3495 ufshcd_dev_man_unlock(hba); 3496 + WARN_ONCE(err > 0, "Incorrect return value %d > 0\n", err); 3509 3497 return err; 3510 3498 } 3511 3499 ··· 3521 3507 * @attr_val: the attribute value after the query request 3522 3508 * completes 3523 3509 * 3524 - * Return: 0 for success, non-zero in case of failure. 3510 + * Return: 0 for success; < 0 upon failure. 3525 3511 */ 3526 3512 int ufshcd_query_attr_retry(struct ufs_hba *hba, 3527 3513 enum query_opcode opcode, enum attr_idn idn, u8 index, u8 selector, ··· 3544 3530 dev_err(hba->dev, 3545 3531 "%s: query attribute, idn %d, failed with error %d after %d retries\n", 3546 3532 __func__, idn, ret, QUERY_REQ_RETRIES); 3533 + WARN_ONCE(ret > 0, "Incorrect return value %d > 0\n", ret); 3547 3534 return ret; 3548 3535 } 3549 3536 3537 + /* 3538 + * Return: 0 if successful; < 0 upon failure. 3539 + */ 3550 3540 static int __ufshcd_query_descriptor(struct ufs_hba *hba, 3551 3541 enum query_opcode opcode, enum desc_idn idn, u8 index, 3552 3542 u8 selector, u8 *desc_buf, int *buf_len) ··· 3608 3590 out_unlock: 3609 3591 hba->dev_cmd.query.descriptor = NULL; 3610 3592 ufshcd_dev_man_unlock(hba); 3593 + WARN_ONCE(err > 0, "Incorrect return value %d > 0\n", err); 3611 3594 return err; 3612 3595 } 3613 3596 ··· 3625 3606 * The buf_len parameter will contain, on return, the length parameter 3626 3607 * received on the response. 3627 3608 * 3628 - * Return: 0 for success, non-zero in case of failure. 3609 + * Return: 0 for success; < 0 upon failure. 3629 3610 */ 3630 3611 int ufshcd_query_descriptor_retry(struct ufs_hba *hba, 3631 3612 enum query_opcode opcode, ··· 3643 3624 break; 3644 3625 } 3645 3626 3627 + WARN_ONCE(err > 0, "Incorrect return value %d > 0\n", err); 3646 3628 return err; 3647 3629 } 3648 3630 ··· 3656 3636 * @param_read_buf: pointer to buffer where parameter would be read 3657 3637 * @param_size: sizeof(param_read_buf) 3658 3638 * 3659 - * Return: 0 in case of success, non-zero otherwise. 3639 + * Return: 0 in case of success; < 0 upon failure. 3660 3640 */ 3661 3641 int ufshcd_read_desc_param(struct ufs_hba *hba, 3662 3642 enum desc_idn desc_id, ··· 3723 3703 out: 3724 3704 if (is_kmalloc) 3725 3705 kfree(desc_buf); 3706 + WARN_ONCE(ret > 0, "Incorrect return value %d > 0\n", ret); 3726 3707 return ret; 3727 3708 } 3728 3709 ··· 3837 3816 * @param_read_buf: pointer to buffer where parameter would be read 3838 3817 * @param_size: sizeof(param_read_buf) 3839 3818 * 3840 - * Return: 0 in case of success, non-zero otherwise. 3819 + * Return: 0 in case of success; < 0 upon failure. 3841 3820 */ 3842 3821 static inline int ufshcd_read_unit_desc_param(struct ufs_hba *hba, 3843 3822 int lun, ··· 4815 4794 * 3. Program UTRL and UTMRL base address 4816 4795 * 4. Configure run-stop-registers 4817 4796 * 4818 - * Return: 0 on success, non-zero value on failure. 4797 + * Return: 0 if successful; < 0 upon failure. 4819 4798 */ 4820 4799 int ufshcd_make_hba_operational(struct ufs_hba *hba) 4821 4800 {