error: a label can only be part of a statement and a declaration is not a statement

在开发代码中使用switch出现的一个编译错误:

error: a label can only be part of a statement and a declaration is not a statement

代码片段如下所示:

    switch(cmd)
    {
        case EDMA3_DRV_IOCTL_DMA_BUFFER_ALLOC:

            dma_buf_info_t *dma_buf_info = (dma_buf_info_t *)arg;
            
            if(NULL == dma_buf_info
                || NULL == dma_buf_info->buf_info)
            {
                RPT(RPT_ERR, "null pointer,err");
                return -1;
            }

            for(i=0; i<dma_buf_info->num_buffers; i++)
            {
                dma_buf_info->buf_info[i].virtAddr_kernel_space = (uint8_t *)dma_alloc_coherent(NULL, 
                                                         dma_buf_info->buffer_size, 
                                                         (dma_addr_t *)&dma_buf_info->buf_info[i].phyAddr, 
                                                         GFP_KERNEL);
                if(0 == dma_buf_info->buf_info[i].phyAddr)
                {
                    RPT(RPT_ERR, "alloc dma buffer,error!!  phyAddr == 0");
                    return -1;
                }

                RPT(RPT_DBG,
                "Allocated DMA phy memory: Phy Address: 0x%llx Virtual Address :0x%p Size :0x%x successfull!!",
                                                            dma_buf_info->buf_info[i].phyAddr,
                                                            dma_buf_info->buf_info[i].virtAddr_kernel_space, 
                                                           (unsigned int)dma_buf_info->buffer_size);
            }
 
            break;

修改方法,在case 后加大括号将代码括起来,如下所示

    switch(cmd)
    {
        case EDMA3_DRV_IOCTL_DMA_BUFFER_ALLOC:
        {
            dma_buf_info_t *dma_buf_info = (dma_buf_info_t *)arg;
            
            if(NULL == dma_buf_info
                || NULL == dma_buf_info->buf_info)
            {
                RPT(RPT_ERR, "null pointer,err");
                return -1;
            }

            for(i=0; i<dma_buf_info->num_buffers; i++)
            {
                dma_buf_info->buf_info[i].virtAddr_kernel_space = (uint8_t *)dma_alloc_coherent(NULL, 
                                                         dma_buf_info->buffer_size, 
                                                         (dma_addr_t *)&dma_buf_info->buf_info[i].phyAddr, 
                                                         GFP_KERNEL);
                if(0 == dma_buf_info->buf_info[i].phyAddr)
                {
                    RPT(RPT_ERR, "alloc dma buffer,error!!  phyAddr == 0");
                    return -1;
                }

                RPT(RPT_DBG,
                "Allocated DMA phy memory: Phy Address: 0x%llx Virtual Address :0x%p Size :0x%x successfull!!",
                                                            dma_buf_info->buf_info[i].phyAddr,
                                                            dma_buf_info->buf_info[i].virtAddr_kernel_space, 
                                                           (unsigned int)dma_buf_info->buffer_size);
            }
        }   
            break;

解决

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值