現在、interface(2019年1月号)を参考にultra96でyolov3の高速化をしています。dma_simple.hとdma_simple.cを含めてmakeを行うとwarningが出ました。
warning
./src/dma_simple.c: In function 'udmabuf_open':
./src/dma_simple.c:18:12: warning: pointer targets in passing argument 1 of 'sscanf' differ in signedness [-Wpointer-sign]
sscanf(attr, "%x", &udmabuf->phys_addr);
^~~~
In file included from /usr/include/features.h:423:0,
from /usr/include/bits/libc-header-start.h:33,
from /usr/include/stdio.h:27,
from ./src/dma_simple.h:1,
from ./src/dma_simple.c:1:
/usr/include/stdio.h:400:12: note: expected 'const char * restrict' but argument is of type 'unsigned char *'
extern int __REDIRECT_NTH (sscanf, (const char *__restrict __s,
^
./src/dma_simple.c:18:20: warning: format '%x' expects argument of type 'unsigned int *', but argument 3 has type 'long unsigned int *' [-Wformat=]
sscanf(attr, "%x", &udmabuf->phys_addr);
~^ ~~~~~~~~~~~~~~~~~~~
%lx
./src/dma_simple.c:27:12: warning: pointer targets in passing argument 1 of 'sscanf' differ in signedness [-Wpointer-sign]
sscanf(attr, "%d", &udmabuf->buf_size);
^~~~
In file included from /usr/include/features.h:423:0,
from /usr/include/bits/libc-header-start.h:33,
from /usr/include/stdio.h:27,
from ./src/dma_simple.h:1,
from ./src/dma_simple.c:1:
/usr/include/stdio.h:400:12: note: expected 'const char * restrict' but argument is of type 'unsigned char *'
extern int __REDIRECT_NTH (sscanf, (const char *__restrict __s,
^
おそらくudmabufの型の形が一致してないことでなっているかと思いますが、どこを修正すべきかわかりません。
dma_simple.h
struct udmabuf {
char name[128];
int file;
unsigned char* buf;
unsigned int buf_size;
unsigned long phys_addr;
unsigned long debug_vma;
unsigned long sync_mode;
};
int udmabuf_open(struct udmabuf* udmabuf, const char* name);
int udmabuf_close(struct udmabuf* udmabuf);
dma_simple.c
#include "dma_simple.h"
int udmabuf_open(struct udmabuf* udmabuf, const char* name)
{
char file_name[1024];
int fd;
unsigned char attr[1024];
strcpy(udmabuf->name, name);
udmabuf->file = -1;
sprintf(file_name, "/sys/class/udmabuf/%s/phys_addr", name);
if ((fd = open(file_name, O_RDONLY)) == -1) {
printf("Can not open %s\n", file_name);
return (-1);
}
read(fd, (void*)attr, 1024);
sscanf(attr, "%x", &udmabuf->phys_addr);
close(fd);
sprintf(file_name, "/sys/class/udmabuf/%s/size", name);
if ((fd = open(file_name, O_RDONLY)) == -1) {
printf("Can not open %s\n", file_name);
return (-1);
}
read(fd, (void*)attr, 1024);
sscanf(attr, "%d", &udmabuf->buf_size);
close(fd);
sprintf(file_name, "/dev/%s", name);
if ((udmabuf->file = open(file_name, O_RDWR | O_SYNC)) == -1) {
printf("Can not open %s\n", file_name);
return (-1);
}
udmabuf->buf = mmap(NULL, udmabuf->buf_size, PROT_READ|PROT_WRITE, MAP_SHARED, udmabuf->file, 0);
udmabuf->debug_vma = 0;
udmabuf->sync_mode = 1;
return 0;
}
int udmabuf_close(struct udmabuf* udmabuf)
{
if (udmabuf->file < 0)
return -1;
close(udmabuf->file);
udmabuf->file = -1;
return 0;
}
Makefile
はビルドの手順を記述したファイルに過ぎないので、「Makefile が Warning を表示する」という表現は適切でない気がします。実際に Warning を表示しているのは コンパイラ (恐らくgcc)ですよね? / 質問のタイトルも、表示された警告メッセージにフォーカスしたものを付けておくと、より伝わりやすいと思います。参考: 良い質問をするには?