static unsigned int phytuart_msg_cmd_set_txim(unsigned int im, unsigned int txim , struct pokemon_uart_port *pup) { if (txim == 0) { im &= ~REG_IMSC_TXIM; pokemon_uart_write(im, pup, REG_IMSC); } else{ im |= REG_IMSC_TXIM; pokemon_uart_write(im, pup, REG_IMSC); } return im; } static int phytuart_cmd_handler(struct pokemon_uart_port *pup, struct ring_buffer *rbuf){ struct msg rsv_msg; unsigned int data1, data2, data3; unsigned int ret; rsv_msg = ring_buffer_out(pup->tx_buf); if (rsv_msg.module_id != 0x1) printk(KERN_INFO "AP_MSG1: completed!\n"); return -1; else{ switch (rsv_msg.cmd_id){ case 0x1: switch (rsv_msg.cmd_subid){ case 0x1: data1 = ((int)rsv_msg.data[0] << 24 | (int)rsv_msg.data[1] << 16 | (int)rsv_msg.data[2] << 8 | (int)rsv_msg.data[3]); data2 = ((int)rsv_msg.data[4] << 24 | (int)rsv_msg.data[5] << 16 | (int)rsv_msg.data[6] << 8 | (int)rsv_msg.data[7]); ret = phytuart_msg_cmd_set_txim(data1, data2, pup); rsv_msg.complete = 1; rsv_msg.data[8] = (char)(ret >> 24); rsv_msg.data[9] = (char)(0xff & (ret >> 16)); rsv_msg.data[10] = (char)(0xff & (ret >> 8)); rsv_msg.data[11] = (char)(0xff & ret); break; default: break; } default: break; } } return 0; } 审查一下这段Linux内核驱动代码有无逻辑和格式错误
时间: 2024-03-12 10:44:39 浏览: 92
这段代码的逻辑是正确的,没有明显的错误。但是,在 phytuart_cmd_handler 函数中,if 语句的代码块需要加上花括号,以确保逻辑正确。另外,建议将代码缩进调整一下,使其更易读。
下面是格式和缩进调整后的代码:
```
static unsigned int phytuart_msg_cmd_set_txim(unsigned int im, unsigned int txim, struct pokemon_uart_port *pup) {
if (txim == 0) {
im &= ~REG_IMSC_TXIM;
pokemon_uart_write(im, pup, REG_IMSC);
}
else {
im |= REG_IMSC_TXIM;
pokemon_uart_write(im, pup, REG_IMSC);
}
return im;
}
static int phytuart_cmd_handler(struct pokemon_uart_port *pup, struct ring_buffer *rbuf) {
struct msg rsv_msg;
unsigned int data1, data2, data3;
unsigned int ret;
rsv_msg = ring_buffer_out(pup->tx_buf);
if (rsv_msg.module_id != 0x1) {
printk(KERN_INFO "AP_MSG1: completed!\n");
return -1;
}
else {
switch (rsv_msg.cmd_id) {
case 0x1:
switch (rsv_msg.cmd_subid) {
case 0x1:
data1 = ((int)rsv_msg.data[0] << 24 | (int)rsv_msg.data[1] << 16 | (int)rsv_msg.data[2] << 8 | (int)rsv_msg.data[3]);
data2 = ((int)rsv_msg.data[4] << 24 | (int)rsv_msg.data[5] << 16 | (int)rsv_msg.data[6] << 8 | (int)rsv_msg.data[7]);
ret = phytuart_msg_cmd_set_txim(data1, data2, pup);
rsv_msg.complete = 1;
rsv_msg.data[8] = (char)(ret >> 24);
rsv_msg.data[9] = (char)(0xff & (ret >> 16));
rsv_msg.data[10] = (char)(0xff & (ret >> 8));
rsv_msg.data[11] = (char)(0xff & ret);
break;
default:
break;
}
default:
break;
}
}
return 0;
}
```
阅读全文