struct nand_ecclayout_user usrlay;
int fd, ret;
- if (stat(node, &st))
+ fd = open(node, O_RDONLY);
+ if (fd == -1)
return sys_errmsg("cannot open \"%s\"", node);
+ if (fstat(fd, &st)) {
+ ret = sys_errmsg("cannot open \"%s\"", node);
+ goto out_close;
+ }
+
if (!S_ISCHR(st.st_mode)) {
errno = EINVAL;
- return errmsg("\"%s\" is not a character device", node);
+ ret = errmsg("\"%s\" is not a character device", node);
+ goto out_close;
}
- fd = open(node, O_RDONLY);
- if (fd == -1)
- return sys_errmsg("cannot open \"%s\"", node);
-
ret = ioctl(fd, ECCGETLAYOUT, &usrlay);
if (ret < 0) {
if (errno == EOPNOTSUPP)
loff_t offs = 0;
struct proc_parse_info pi;
- if (stat(node, &st)) {
+ fd = open(node, O_RDONLY);
+ if (fd == -1) {
sys_errmsg("cannot open \"%s\"", node);
if (errno == ENOENT)
normsg("MTD subsystem is old and does not support "
"sysfs, so MTD character device nodes have "
"to exist");
+ return -1;
+ }
+
+ if (fstat(fd, &st)) {
+ sys_errmsg("cannot stat \"%s\"", node);
+ close(fd);
+ return -1;
}
if (!S_ISCHR(st.st_mode)) {
+ close(fd);
errno = EINVAL;
return errmsg("\"%s\" is not a character device", node);
}
mtd->minor = minor(st.st_rdev);
if (mtd->major != MTD_DEV_MAJOR) {
+ close(fd);
errno = EINVAL;
return errmsg("\"%s\" has major number %d, MTD devices have "
"major %d", node, mtd->major, MTD_DEV_MAJOR);
mtd->mtd_num = mtd->minor / 2;
- fd = open(node, O_RDONLY);
- if (fd == -1)
- return sys_errmsg("cannot open \"%s\"", node);
-
if (ioctl(fd, MEMGETINFO, &ui)) {
sys_errmsg("MEMGETINFO ioctl request failed");
goto out_close;
exit(errflg > 0 ? 0 : EXIT_FAILURE);
}
- if (stat(argv[optind], &buf) != 0) {
+ fd = open(argv[optind], O_RDONLY);
+ if (fd == -1) {
+ perror("open failed");
+ exit(EXIT_FAILURE);
+ }
+ if (fstat(fd, &buf) != 0) {
perror("status check failed");
+ close(fd);
exit(EXIT_FAILURE);
}
if (!(buf.st_mode & S_IFCHR)) {
fprintf(stderr, "%s is not a character special device\n",
argv[optind]);
- exit(EXIT_FAILURE);
- }
- fd = open(argv[optind], O_RDONLY);
- if (fd == -1) {
- perror("open failed");
+ close(fd);
exit(EXIT_FAILURE);
}
exit(errflg > 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
- if (stat(argv[optind], &buf) != 0) {
+ fd = open(argv[optind], O_RDWR);
+ if (fd == -1) {
+ perror("open failed");
+ exit(EXIT_FAILURE);
+ }
+ if (fstat(fd, &buf) != 0) {
perror("status check failed");
+ close(fd);
exit(EXIT_FAILURE);
}
if (!(buf.st_mode & S_IFCHR)) {
fprintf(stderr, "%s is not a character special device\n",
argv[optind]);
- exit(EXIT_FAILURE);
- }
- fd = open(argv[optind], O_RDWR);
- if (fd == -1) {
- perror("open failed");
+ close(fd);
exit(EXIT_FAILURE);
}