diff mbox series

cxl/mbox: Code readability improvement

Message ID 20240130055844.19811-1-caoqq@fujitsu.com
State New, archived
Headers show
Series cxl/mbox: Code readability improvement | expand

Commit Message

Cao, Quanquan/曹 全全 Jan. 30, 2024, 5:58 a.m. UTC
"send_cmd->id == 0" indicates an invalid command, so replace 0
to CXL_MEM_COMMAND_ID_INVALID to make it easy for reading/understanding.

Signed-off-by: Quanquan Cao <caoqq@fujitsu.com>
---
 drivers/cxl/core/mbox.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Dan Williams Jan. 30, 2024, 6:59 a.m. UTC | #1
Quanquan Cao wrote:
> "send_cmd->id == 0" indicates an invalid command, so replace 0
> to CXL_MEM_COMMAND_ID_INVALID to make it easy for reading/understanding.
> 
> Signed-off-by: Quanquan Cao <caoqq@fujitsu.com>
> ---
>  drivers/cxl/core/mbox.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c
> index 27166a411705..2e5ee05011d6 100644
> --- a/drivers/cxl/core/mbox.c
> +++ b/drivers/cxl/core/mbox.c
> @@ -485,7 +485,8 @@ static int cxl_validate_cmd_from_user(struct cxl_mbox_cmd *mbox_cmd,
>  	struct cxl_mem_command mem_cmd;
>  	int rc;
>  
> -	if (send_cmd->id == 0 || send_cmd->id >= CXL_MEM_COMMAND_ID_MAX)

"non-zero" is readable to me, and less characters to parse means current
code is literally easier to read.
Cao, Quanquan/曹 全全 Jan. 30, 2024, 8:28 a.m. UTC | #2
> Quanquan Cao wrote:
>> "send_cmd->id == 0" indicates an invalid command, so replace 0
>> to CXL_MEM_COMMAND_ID_INVALID to make it easy for reading/understanding.
>>
>> Signed-off-by: Quanquan Cao <caoqq@fujitsu.com>
>> ---
>>   drivers/cxl/core/mbox.c | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c
>> index 27166a411705..2e5ee05011d6 100644
>> --- a/drivers/cxl/core/mbox.c
>> +++ b/drivers/cxl/core/mbox.c
>> @@ -485,7 +485,8 @@ static int cxl_validate_cmd_from_user(struct cxl_mbox_cmd *mbox_cmd,
>>   	struct cxl_mem_command mem_cmd;
>>   	int rc;
>>   
>> -	if (send_cmd->id == 0 || send_cmd->id >= CXL_MEM_COMMAND_ID_MAX)
> 
> "non-zero" is readable to me, and less characters to parse means current
> code is literally easier to read.

Thanks, I got.
diff mbox series

Patch

diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c
index 27166a411705..2e5ee05011d6 100644
--- a/drivers/cxl/core/mbox.c
+++ b/drivers/cxl/core/mbox.c
@@ -485,7 +485,8 @@  static int cxl_validate_cmd_from_user(struct cxl_mbox_cmd *mbox_cmd,
 	struct cxl_mem_command mem_cmd;
 	int rc;
 
-	if (send_cmd->id == 0 || send_cmd->id >= CXL_MEM_COMMAND_ID_MAX)
+	if (send_cmd->id == CXL_MEM_COMMAND_ID_INVALID ||
+	    send_cmd->id >= CXL_MEM_COMMAND_ID_MAX)
 		return -ENOTTY;
 
 	/*