fake-input-accelerometer: Simplify error paths
This commit is contained in:
@@ -59,19 +59,15 @@ write_sysfs_string (char *filename,
|
|||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
g_autoptr(FILE) sysfsfp = NULL;
|
g_autoptr(FILE) sysfsfp = NULL;
|
||||||
char *temp;
|
g_autofree char *temp = NULL;
|
||||||
|
|
||||||
temp = g_build_filename (basedir, filename, NULL);
|
temp = g_build_filename (basedir, filename, NULL);
|
||||||
sysfsfp = fopen (temp, "w");
|
sysfsfp = fopen (temp, "w");
|
||||||
if (sysfsfp == NULL) {
|
if (sysfsfp == NULL) {
|
||||||
ret = -errno;
|
ret = -errno;
|
||||||
goto error_free;
|
return ret;
|
||||||
}
|
}
|
||||||
fprintf(sysfsfp, "%s", val);
|
fprintf(sysfsfp, "%s", val);
|
||||||
|
|
||||||
error_free:
|
|
||||||
g_free(temp);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +114,7 @@ static gboolean
|
|||||||
setup_uinput (OrientationData *data)
|
setup_uinput (OrientationData *data)
|
||||||
{
|
{
|
||||||
struct uinput_dev dev;
|
struct uinput_dev dev;
|
||||||
int fd;
|
g_auto(IioFd) fd = -1;
|
||||||
|
|
||||||
fd = open("/dev/uinput", O_RDWR);
|
fd = open("/dev/uinput", O_RDWR);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
@@ -138,13 +134,13 @@ setup_uinput (OrientationData *data)
|
|||||||
|
|
||||||
if (write (fd, &dev, sizeof(dev)) != sizeof(dev)) {
|
if (write (fd, &dev, sizeof(dev)) != sizeof(dev)) {
|
||||||
g_warning ("Error creating uinput device");
|
g_warning ("Error creating uinput device");
|
||||||
goto bail;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* enabling key events */
|
/* enabling key events */
|
||||||
if (ioctl (fd, UI_SET_EVBIT, EV_ABS) < 0) {
|
if (ioctl (fd, UI_SET_EVBIT, EV_ABS) < 0) {
|
||||||
g_warning ("Error enabling uinput absolute events");
|
g_warning ("Error enabling uinput absolute events");
|
||||||
goto bail;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* enabling keys */
|
/* enabling keys */
|
||||||
@@ -152,22 +148,18 @@ setup_uinput (OrientationData *data)
|
|||||||
ioctl (fd, UI_SET_ABSBIT, ABS_Y) < 0 ||
|
ioctl (fd, UI_SET_ABSBIT, ABS_Y) < 0 ||
|
||||||
ioctl (fd, UI_SET_ABSBIT, ABS_Z) < 0) {
|
ioctl (fd, UI_SET_ABSBIT, ABS_Z) < 0) {
|
||||||
g_warning ("Couldn't enable uinput axis");
|
g_warning ("Couldn't enable uinput axis");
|
||||||
goto bail;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* creating the device */
|
/* creating the device */
|
||||||
if (ioctl (fd, UI_DEV_CREATE) < 0) {
|
if (ioctl (fd, UI_DEV_CREATE) < 0) {
|
||||||
g_warning ("Error creating uinput device");
|
g_warning ("Error creating uinput device");
|
||||||
goto bail;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
data->uinput = fd;
|
data->uinput = fd;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
bail:
|
|
||||||
close (fd);
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Reference in New Issue
Block a user