[PATCH] KDrive: Fix error handlig in tslib driver
Jeremy Huddleston
jeremyhu at apple.com
Mon Oct 25 13:58:56 PDT 2010
This looks mostly fine, but you're no longer validating private->fd ... you need a:
if(private->fd < 0)
return BadAlloc;
On Oct 17, 2010, at 14:02, Paulius Zaleckas wrote:
> If ts_open() fails and return NULL, then next call to ts_fd()
> segfaults because of NULL dereference. There is no need to
> check output of ts_fd() as ts_open() did this internally.
>
> Signed-off-by: Paulius Zaleckas <paulius.zaleckas at gmail.com>
> ---
>
> hw/kdrive/linux/tslib.c | 15 +++++++++++----
> 1 files changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/hw/kdrive/linux/tslib.c b/hw/kdrive/linux/tslib.c
> index 48a0842..570cbf9 100644
> --- a/hw/kdrive/linux/tslib.c
> +++ b/hw/kdrive/linux/tslib.c
> @@ -117,15 +117,22 @@ TslibEnable (KdPointerInfo *pi)
> pi->path = strdup("/dev/input/touchscreen0");
> ErrorF("[tslib/TslibEnable] no device path given, trying %s\n", pi->path);
> }
> +
> private->tsDev = ts_open(pi->path, 0);
> - private->fd = ts_fd(private->tsDev);
> - if (!private->tsDev || ts_config(private->tsDev) || private->fd < 0) {
> + if (!private->tsDev) {
> ErrorF("[tslib/TslibEnable] failed to open %s\n", pi->path);
> - if (private->fd >= 0)
> - close(private->fd);
> return BadAlloc;
> }
>
> + if (ts_config(private->tsDev)) {
> + ErrorF("[tslib/TslibEnable] failed to load configuration\n");
> + ts_close(private->tsDev);
> + private->tsDev = NULL;
> + return BadValue;
> + }
> +
> + private->fd = ts_fd(private->tsDev);
> +
> KdRegisterFd(private->fd, TsRead, pi);
>
> return Success;
>
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
More information about the xorg-devel
mailing list