Question

I have a question for transfer parameter want to consult,

I need to transfer some parameters from user space to kernel space, but one of them lost(the value incorrect when i check it from kernel space). But i don't have any idea why it lost.

Below is some of my code and log, the lost parameter is the write_flag, i set write_flag as integer number(2) in user space.

But when i print write_flag in kernel space it totally wrong(1651866136). some parameter were transferred without problem like the opcode and the arg.

[  859.877750] user.write_flag:1651866136, idata->ic.write_flag:1651866136      
[  859.883133] user.opcode:8, idata->ic.opcode:8                                
[  859.887421] user.arg:0, idata->ic.arg:0   

Have anyone can give my some idea to fix this issue, the data type for write_flag is int, opcode and arg is __u32.

Thanks.

HAL side:

LOGI("dev->fd:%d, cmd_idx:%d, arg:%d.",dev->fd,mmc_local_cmd->opcode, mmc_local_cmd->arg);
LOGI("dev->write_flag:%d.",mmc_local_cmd->write_flag);
ret = ioctl(dev->fd,MMC_IOC_CMD,&mmc_local_cmd);

Kernel side:

if (copy_from_user(&idata->ic, user, sizeof(idata->ic))) {
    err = -EFAULT;
    goto idata_err;
}
/*FIXME: write_flag is incorrect before copy_from_user execute */
printk("user.write_flag:%d, idata->ic.write_flag:%d\n",user->write_flag, idata->ic.write_flag);
printk("user.opcode:%d, idata->ic.opcode:%d\n",user->opcode, idata->ic.opcode);
printk("user.arg:%d, idata->ic.arg:%d\n",user->arg, idata->ic.arg);
Was it helpful?

Solution

I fixed the issue by remove the & because we don't need to Reference here.

ret = ioctl(dev->fd,MMC_IOC_CMD,mmc_local_cmd);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top