循环函数给出带有值的“return”错误,函数返回void“

时间:2013-09-26 01:09:52

标签: c++ c kernel

原始代码是

#define MAX_FRAMES 10000
#define MS_BETWEEN_FRAMES CONFIG_FB_MSM_LOGO_ANIMATE_FPS

int load_565rle_image(char *filename, bool bf_supported);
struct delayed_work rle_animate_work;

static void load_565rle_animate(struct work_struct *work)
{
    int i, ret = 0, bf_supported = 0;
    char filename [20];
    struct fb_info *info = registered_fb[0];
    set_fs(KERNEL_DS);
    printk(KERN_INFO "Starting kernel boot animation\n");
    for (i = 1; i < MAX_FRAMES; i++) {
        sprintf(filename, "/res/bootlogo/%d.rle", i);
        ret = load_565rle_image(filename, bf_supported);
        sys_unlink(filename);
        if (ret == -ENOENT)
            break;
        info->fbops->fb_open(info, 0);
        info->fbops->fb_pan_display(&info->var, info);
        msleep(MS_BETWEEN_FRAMES);
    }
}

static int __init logo_animate_init(void)
{
    INIT_DELAYED_WORK(&rle_animate_work, load_565rle_animate);
    schedule_delayed_work(&rle_animate_work, 5 * HZ);
    return 0;
}

static void __exit logo_animate_exit(void)
{
    return;
}

通过连续加载* .rle图像系列来制作内核徽标,即1.rle&gt; 2.rle&gt; 3.rle&gt; 4.rle&gt; 5.rle等等。

最初写入的方式是在图像文件名结束时停止加载这些图像,即如果最后一个文件名为5.rle,则停止并停止。 基本上,我现在尝试做的是循环,当它到达最后一个文件(5.rle)时,它将再次从头开始加载(1.rle)。

所以我添加了CONFIG_FB_MSM_LOGO_ANIMATE_LOOP

static void load_565rle_animate(struct work_struct *work)
{
    int i, ret = 0, bf_supported = 0;
    char filename [20];
    struct fb_info *info = registered_fb[0];
    set_fs(KERNEL_DS);
    printk(KERN_INFO "Starting kernel boot animation\n");
    for (i = 1; i < MAX_FRAMES; i++) {
        sprintf(filename, "/res/bootlogo/%d.rle", i);
        ret = load_565rle_image(filename, bf_supported);
        sys_unlink(filename);
        if (ret == -ENOENT)
#ifdef CONFIG_FB_MSM_LOGO_ANIMATE_LOOP
            return ret;
#else
            break;
#endif
        info->fbops->fb_open(info, 0);
        info->fbops->fb_pan_display(&info->var, info);
        msleep(MS_BETWEEN_FRAMES);
    }
}

但是当启用CONFIG_FB_MSM_LOGO_ANIMATE_LOOP时,它会给出编译错误&#39;警告:'return'带一个值,函数返回void [默认启用]&#39; 这停止了​​编译过程。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

#ifdef CONFIG_FB_MSM_LOGO_ANIMATE_LOOP
            return ret;
 #else
        break;
 #endif

这是由预处理程序预处理的,并且在定义CONFIG_FB_MSM_LOGO_ANIMATE_LOOP时会导致从函数返回int ret。所以

  

'return',带一个值,函数返回void

似乎是非常合理的暗示。

溶液: 更改函数返回类型然后或将其更改为:

#ifdef `CONFIG_FB_MSM_LOGO_ANIMATE_LOOP`
            return;
 #else
        break;
 #endif