[Cbe-oss-dev] [PATCH 2/2] libspe2: Fix errno set by spe_context_create

Kazunori Asayama asayama at sm.sony.co.jp
Tue Oct 2 18:02:10 EST 2007


The current implementation of libspe sets incorrect value to errno in
some cases because of the following reasons:

  - errno returned by the spu_create system call is overwritten by the
    cleaning up procedure.

  - some special errnos, e.g. EINVAL, are not treated as special
    cases.

This patch fixes this problem.

Signed-off-by: Kazunori Asayama <asayama at sm.sony.co.jp>

---
 spebase/create.c |   16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

Index: b/spebase/create.c
===================================================================
--- a/spebase/create.c	2007-08-28 10:40:33.000000000 +0900
+++ b/spebase/create.c	2007-09-19 23:39:04.000000000 +0900
@@ -261,12 +261,24 @@ spe_context_ptr_t _base_spe_context_crea
 			S_IRUSR | S_IWUSR | S_IXUSR, aff_spe_fd);
 
 	if (priv->fd_spe_dir < 0) {
+		int errno_saved = errno; /* save errno to prevent being overwritten */
 		DEBUG_PRINTF("ERROR: Could not create SPE %s\n", pathname);
 		perror("spu_create()");
 		free_spe_context(spe);
-		/* we mask most errors, but leave ENODEV */
-		if (errno != ENODEV)
+		/* we mask most errors, but leave ENODEV, etc */
+		switch (errno_saved) {
+		case ENOTSUP:
+		case EEXIST:
+		case EINVAL:
+		case EBUSY:
+		case EPERM:
+		case ENODEV:
+			errno = errno_saved; /* restore errno */
+			break;
+		default:
 			errno = EFAULT;
+			break;
+		}
 		return NULL;
 	}
 



More information about the cbe-oss-dev mailing list