From f5174e9f8b4dc3ea7d3153340d46bf29980b5bce Mon Sep 17 00:00:00 2001
From: Phil Sutter <phil.sutter@viprinet.com>
Date: Thu, 17 Jun 2010 14:45:17 +0200
Subject: [PATCH 047/291] cryptodev: ioctl_compat:

---
 drivers/staging/crypto/cryptodev/cryptodev.h      | 38 -----------------------
 drivers/staging/crypto/cryptodev/cryptodev_int.h  | 36 +++++++++++++++++++++
 drivers/staging/crypto/cryptodev/cryptodev_main.c |  7 +++++
 3 files changed, 43 insertions(+), 38 deletions(-)

diff --git a/drivers/staging/crypto/cryptodev/cryptodev.h b/drivers/staging/crypto/cryptodev/cryptodev.h
index f7493112aa74..572b3c30dc76 100644
--- a/drivers/staging/crypto/cryptodev/cryptodev.h
+++ b/drivers/staging/crypto/cryptodev/cryptodev.h
@@ -150,42 +150,4 @@ typedef enum {
 #define CIOCKEY         _IOWR('c', 105, struct crypt_kop)
 #define CIOCASYMFEAT    _IOR('c', 106, uint32_t)
 
-/* compatibility code for 32bit userlands */
-
-#ifdef __KERNEL__
-#ifdef CONFIG_COMPAT
-
-/* input of CIOCGSESSION */
-struct compat_session_op {
-	/* Specify either cipher or mac
-	 */
-	uint32_t	cipher;		/* cryptodev_crypto_op_t */
-	uint32_t	mac;		/* cryptodev_crypto_op_t */
-
-	uint32_t	keylen;
-	uint32_t	key;		/* pointer to key data */
-	uint32_t	mackeylen;
-	uint32_t	mackey;		/* pointer to mac key data */
-
-	uint32_t	ses;		/* session identifier */
-};
-
-/* input of CIOCCRYPT */
- struct compat_crypt_op {
-	uint32_t	ses;		/* session identifier */
-	uint16_t	op;		/* COP_ENCRYPT or COP_DECRYPT */
-	uint16_t	flags;		/* no usage so far, use 0 */
-	uint32_t	len;		/* length of source data */
-	uint32_t	src;		/* source data */
-	uint32_t	dst;		/* pointer to output data */
-	uint32_t	mac;		/* pointer to output data for hash/MAC operations */
-	uint32_t	iv;		/* initialization vector for encryption operations */
-};
-
-#define COMPAT_CIOCGSESSION    _IOWR('c', 102, struct compat_session_op)
-#define COMPAT_CIOCCRYPT       _IOWR('c', 104, struct compat_crypt_op)
-
-#endif /* CONFIG_COMPAT */
-#endif /* __KERNEL__ */
-
 #endif /* L_CRYPTODEV_H */
diff --git a/drivers/staging/crypto/cryptodev/cryptodev_int.h b/drivers/staging/crypto/cryptodev/cryptodev_int.h
index bad332ca33b1..8e3059a553d6 100644
--- a/drivers/staging/crypto/cryptodev/cryptodev_int.h
+++ b/drivers/staging/crypto/cryptodev/cryptodev_int.h
@@ -60,4 +60,40 @@ int cryptodev_hash_reset( struct hash_data* hdata);
 void cryptodev_hash_deinit(struct hash_data* hdata);
 int cryptodev_hash_init( struct hash_data* hdata, const char* alg_name, int hmac_mode, __user void* mackey, size_t mackeylen);
 
+/* compatibility stuff */
+#ifdef CONFIG_COMPAT
+
+/* input of CIOCGSESSION */
+struct compat_session_op {
+	/* Specify either cipher or mac
+	 */
+	uint32_t	cipher;		/* cryptodev_crypto_op_t */
+	uint32_t	mac;		/* cryptodev_crypto_op_t */
+
+	uint32_t	keylen;
+	uint32_t	key;		/* pointer to key data */
+	uint32_t	mackeylen;
+	uint32_t	mackey;		/* pointer to mac key data */
+
+	uint32_t	ses;		/* session identifier */
+} __attribute__((packed));
+
+/* input of CIOCCRYPT */
+ struct compat_crypt_op {
+	uint32_t	ses;		/* session identifier */
+	uint16_t	op;		/* COP_ENCRYPT or COP_DECRYPT */
+	uint16_t	flags;		/* no usage so far, use 0 */
+	uint32_t	len;		/* length of source data */
+	uint32_t	src;		/* source data */
+	uint32_t	dst;		/* pointer to output data */
+	uint32_t	mac;		/* pointer to output data for hash/MAC operations */
+	uint32_t	iv;		/* initialization vector for encryption operations */
+} __attribute__((packed));
+
+/* compat ioctls, defined for the above structs */
+#define COMPAT_CIOCGSESSION    _IOWR('c', 102, struct compat_session_op)
+#define COMPAT_CIOCCRYPT       _IOWR('c', 104, struct compat_crypt_op)
+
+#endif /* CONFIG_COMPAT */
+
 #endif /* CRYPTODEV_INT_H */
diff --git a/drivers/staging/crypto/cryptodev/cryptodev_main.c b/drivers/staging/crypto/cryptodev/cryptodev_main.c
index d016931c39a4..9fac1e6c068c 100644
--- a/drivers/staging/crypto/cryptodev/cryptodev_main.c
+++ b/drivers/staging/crypto/cryptodev/cryptodev_main.c
@@ -582,6 +582,9 @@ cryptodev_ioctl(struct inode *inode, struct file *filp,
 	}
 }
 
+/* compatibility code for 32bit userlands */
+#ifdef CONFIG_COMPAT
+
 static inline void
 compat_to_session_op(struct compat_session_op *compat, struct session_op *sop)
 {
@@ -674,12 +677,16 @@ cryptodev_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 	}
 }
 
+#endif /* CONFIG_COMPAT */
+
 struct file_operations cryptodev_fops = {
 	.owner = THIS_MODULE,
 	.open = cryptodev_open,
 	.release = cryptodev_release,
 	.ioctl = cryptodev_ioctl,
+#ifdef CONFIG_COMPAT
 	.compat_ioctl = cryptodev_compat_ioctl,
+#endif /* CONFIG_COMPAT */
 };
 
 struct miscdevice cryptodev = {
-- 
2.1.0

