[PATCH] crypto: cleaning and refactoring in rsa.c

2016-03-20 Thread maitesin
* Removed several unused initializations of variables.
* Inlined couple of functions.
* rsa_check_key_length: changed to use only the switch statement.
* rsa_setkey: refactored the implementation to be closer to the other
functions in the file.

Signed-off-by: Oscar Forner Martinez 
---
 crypto/rsa.c | 29 -
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/crypto/rsa.c b/crypto/rsa.c
index 466003e..0832b38 100644
--- a/crypto/rsa.c
+++ b/crypto/rsa.c
@@ -80,8 +80,7 @@ static int rsa_enc(struct akcipher_request *req)
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
const struct rsa_key *pkey = rsa_get_key(tfm);
MPI m, c = mpi_alloc(0);
-   int ret = 0;
-   int sign;
+   int ret, sign;
 
if (!c)
return -ENOMEM;
@@ -128,8 +127,7 @@ static int rsa_dec(struct akcipher_request *req)
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
const struct rsa_key *pkey = rsa_get_key(tfm);
MPI c, m = mpi_alloc(0);
-   int ret = 0;
-   int sign;
+   int ret, sign;
 
if (!m)
return -ENOMEM;
@@ -176,8 +174,7 @@ static int rsa_sign(struct akcipher_request *req)
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
const struct rsa_key *pkey = rsa_get_key(tfm);
MPI m, s = mpi_alloc(0);
-   int ret = 0;
-   int sign;
+   int ret, sign;
 
if (!s)
return -ENOMEM;
@@ -224,8 +221,7 @@ static int rsa_verify(struct akcipher_request *req)
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
const struct rsa_key *pkey = rsa_get_key(tfm);
MPI s, m = mpi_alloc(0);
-   int ret = 0;
-   int sign;
+   int ret, sign;
 
if (!m)
return -ENOMEM;
@@ -277,25 +273,24 @@ static int rsa_check_key_length(unsigned int len)
case 3072:
case 4096:
return 0;
+   default:
+   return -EINVAL;
}
-
-   return -EINVAL;
 }
 
 static int rsa_setkey(struct crypto_akcipher *tfm, const void *key,
  unsigned int keylen)
 {
struct rsa_key *pkey = akcipher_tfm_ctx(tfm);
-   int ret;
+   int ret = rsa_parse_key(pkey, key, keylen);
 
-   ret = rsa_parse_key(pkey, key, keylen);
if (ret)
return ret;
 
-   if (rsa_check_key_length(mpi_get_size(pkey->n) << 3)) {
+   ret = rsa_check_key_length(mpi_get_size(pkey->n) << 3);
+   if (ret)
rsa_free_key(pkey);
-   ret = -EINVAL;
-   }
+
return ret;
 }
 
@@ -322,12 +317,12 @@ static struct akcipher_alg rsa = {
},
 };
 
-static int rsa_init(void)
+static inline int rsa_init(void)
 {
return crypto_register_akcipher();
 }
 
-static void rsa_exit(void)
+static inline void rsa_exit(void)
 {
crypto_unregister_akcipher();
 }
-- 
2.7.3



[PATCH] crypto: cleaning and refactoring in rsa.c

2016-03-20 Thread maitesin
* Removed several unused initializations of variables.
* Inlined couple of functions.
* rsa_check_key_length: changed to use only the switch statement.
* rsa_setkey: refactored the implementation to be closer to the other
functions in the file.

Signed-off-by: Oscar Forner Martinez 
---
 crypto/rsa.c | 29 -
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/crypto/rsa.c b/crypto/rsa.c
index 466003e..0832b38 100644
--- a/crypto/rsa.c
+++ b/crypto/rsa.c
@@ -80,8 +80,7 @@ static int rsa_enc(struct akcipher_request *req)
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
const struct rsa_key *pkey = rsa_get_key(tfm);
MPI m, c = mpi_alloc(0);
-   int ret = 0;
-   int sign;
+   int ret, sign;
 
if (!c)
return -ENOMEM;
@@ -128,8 +127,7 @@ static int rsa_dec(struct akcipher_request *req)
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
const struct rsa_key *pkey = rsa_get_key(tfm);
MPI c, m = mpi_alloc(0);
-   int ret = 0;
-   int sign;
+   int ret, sign;
 
if (!m)
return -ENOMEM;
@@ -176,8 +174,7 @@ static int rsa_sign(struct akcipher_request *req)
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
const struct rsa_key *pkey = rsa_get_key(tfm);
MPI m, s = mpi_alloc(0);
-   int ret = 0;
-   int sign;
+   int ret, sign;
 
if (!s)
return -ENOMEM;
@@ -224,8 +221,7 @@ static int rsa_verify(struct akcipher_request *req)
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
const struct rsa_key *pkey = rsa_get_key(tfm);
MPI s, m = mpi_alloc(0);
-   int ret = 0;
-   int sign;
+   int ret, sign;
 
if (!m)
return -ENOMEM;
@@ -277,25 +273,24 @@ static int rsa_check_key_length(unsigned int len)
case 3072:
case 4096:
return 0;
+   default:
+   return -EINVAL;
}
-
-   return -EINVAL;
 }
 
 static int rsa_setkey(struct crypto_akcipher *tfm, const void *key,
  unsigned int keylen)
 {
struct rsa_key *pkey = akcipher_tfm_ctx(tfm);
-   int ret;
+   int ret = rsa_parse_key(pkey, key, keylen);
 
-   ret = rsa_parse_key(pkey, key, keylen);
if (ret)
return ret;
 
-   if (rsa_check_key_length(mpi_get_size(pkey->n) << 3)) {
+   ret = rsa_check_key_length(mpi_get_size(pkey->n) << 3);
+   if (ret)
rsa_free_key(pkey);
-   ret = -EINVAL;
-   }
+
return ret;
 }
 
@@ -322,12 +317,12 @@ static struct akcipher_alg rsa = {
},
 };
 
-static int rsa_init(void)
+static inline int rsa_init(void)
 {
return crypto_register_akcipher();
 }
 
-static void rsa_exit(void)
+static inline void rsa_exit(void)
 {
crypto_unregister_akcipher();
 }
-- 
2.7.3



[PATCH 0/2] Fix coding style issues and a consistence change.

2015-09-09 Thread Maitesin
Some fixes for coding style issues and consistence in a conditional.

Maitesin (2):
  fs: isofs: Fix a coding style issue and change conditional to make it
consistence
  fs: isofs: Fix several coding style issues

 fs/isofs/compress.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

-- 
2.5.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/2] fs: isofs: Fix a coding style issue and change conditional to make it consistence

2015-09-09 Thread Maitesin
The coding style issue is the white spaces after and before the brackets in the 
for. The change in the conditional is to make it consistence with the other 
ones in the file. All other conditionals are tested like that.

Signed-off-by: Oscar Forner Martinez 
---
 fs/isofs/compress.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/isofs/compress.c b/fs/isofs/compress.c
index f311bf0..5750830 100644
--- a/fs/isofs/compress.c
+++ b/fs/isofs/compress.c
@@ -66,8 +66,8 @@ static loff_t zisofs_uncompress_block(struct inode *inode, 
loff_t block_start,
return 0;
}
/* Empty block? */
-   if (block_size == 0) {
-   for ( i = 0 ; i < pcount ; i++ ) {
+   if (!block_size) {
+   for (i = 0 ; i < pcount ; i++) {
if (!pages[i])
continue;
memset(page_address(pages[i]), 0, PAGE_CACHE_SIZE);
-- 
2.5.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/2] fs: isofs: Fix several coding style issues

2015-09-09 Thread Maitesin
As recommended I fixed several coding style issues related with whitespaces.

Signed-off-by: Oscar Forner Martinez 
---
 fs/isofs/compress.c | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/fs/isofs/compress.c b/fs/isofs/compress.c
index 5750830..107a078 100644
--- a/fs/isofs/compress.c
+++ b/fs/isofs/compress.c
@@ -67,7 +67,7 @@ static loff_t zisofs_uncompress_block(struct inode *inode, 
loff_t block_start,
}
/* Empty block? */
if (!block_size) {
-   for (i = 0 ; i < pcount ; i++) {
+   for (i = 0; i < pcount; i++) {
if (!pages[i])
continue;
memset(page_address(pages[i]), 0, PAGE_CACHE_SIZE);
@@ -103,7 +103,7 @@ static loff_t zisofs_uncompress_block(struct inode *inode, 
loff_t block_start,
 
stream.workspace = zisofs_zlib_workspace;
mutex_lock(_zlib_lock);
-   
+
zerr = zlib_inflateInit();
if (zerr != Z_OK) {
if (zerr == Z_MEM_ERROR)
@@ -134,7 +134,7 @@ static loff_t zisofs_uncompress_block(struct inode *inode, 
loff_t block_start,
*errp = -EIO;
break;
}
-   stream.next_in  = bhs[curbh]->b_data +
+   stream.next_in = bhs[curbh]->b_data +
(block_start & bufmask);
stream.avail_in = min_t(unsigned, bufsize -
(block_start & bufmask),
@@ -353,7 +353,7 @@ static int zisofs_readpage(struct file *file, struct page 
*page)
if (i != full_page)
page_cache_release(pages[i]);
}
-   }   
+   }
 
/* At this point, err contains 0 or -EIO depending on the "critical" 
page */
return err;
@@ -368,9 +368,8 @@ const struct address_space_operations zisofs_aops = {
 int __init zisofs_init(void)
 {
zisofs_zlib_workspace = vmalloc(zlib_inflate_workspacesize());
-   if ( !zisofs_zlib_workspace )
+   if (!zisofs_zlib_workspace)
return -ENOMEM;
-
return 0;
 }
 
-- 
2.5.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/2] fs: isofs: Fix several coding style issues

2015-09-09 Thread Maitesin
As recommended I fixed several coding style issues related with whitespaces.

Signed-off-by: Oscar Forner Martinez 
---
 fs/isofs/compress.c | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/fs/isofs/compress.c b/fs/isofs/compress.c
index 5750830..107a078 100644
--- a/fs/isofs/compress.c
+++ b/fs/isofs/compress.c
@@ -67,7 +67,7 @@ static loff_t zisofs_uncompress_block(struct inode *inode, 
loff_t block_start,
}
/* Empty block? */
if (!block_size) {
-   for (i = 0 ; i < pcount ; i++) {
+   for (i = 0; i < pcount; i++) {
if (!pages[i])
continue;
memset(page_address(pages[i]), 0, PAGE_CACHE_SIZE);
@@ -103,7 +103,7 @@ static loff_t zisofs_uncompress_block(struct inode *inode, 
loff_t block_start,
 
stream.workspace = zisofs_zlib_workspace;
mutex_lock(_zlib_lock);
-   
+
zerr = zlib_inflateInit();
if (zerr != Z_OK) {
if (zerr == Z_MEM_ERROR)
@@ -134,7 +134,7 @@ static loff_t zisofs_uncompress_block(struct inode *inode, 
loff_t block_start,
*errp = -EIO;
break;
}
-   stream.next_in  = bhs[curbh]->b_data +
+   stream.next_in = bhs[curbh]->b_data +
(block_start & bufmask);
stream.avail_in = min_t(unsigned, bufsize -
(block_start & bufmask),
@@ -353,7 +353,7 @@ static int zisofs_readpage(struct file *file, struct page 
*page)
if (i != full_page)
page_cache_release(pages[i]);
}
-   }   
+   }
 
/* At this point, err contains 0 or -EIO depending on the "critical" 
page */
return err;
@@ -368,9 +368,8 @@ const struct address_space_operations zisofs_aops = {
 int __init zisofs_init(void)
 {
zisofs_zlib_workspace = vmalloc(zlib_inflate_workspacesize());
-   if ( !zisofs_zlib_workspace )
+   if (!zisofs_zlib_workspace)
return -ENOMEM;
-
return 0;
 }
 
-- 
2.5.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/2] fs: isofs: Fix a coding style issue and change conditional to make it consistence

2015-09-09 Thread Maitesin
The coding style issue is the white spaces after and before the brackets in the 
for. The change in the conditional is to make it consistence with the other 
ones in the file. All other conditionals are tested like that.

Signed-off-by: Oscar Forner Martinez 
---
 fs/isofs/compress.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/isofs/compress.c b/fs/isofs/compress.c
index f311bf0..5750830 100644
--- a/fs/isofs/compress.c
+++ b/fs/isofs/compress.c
@@ -66,8 +66,8 @@ static loff_t zisofs_uncompress_block(struct inode *inode, 
loff_t block_start,
return 0;
}
/* Empty block? */
-   if (block_size == 0) {
-   for ( i = 0 ; i < pcount ; i++ ) {
+   if (!block_size) {
+   for (i = 0 ; i < pcount ; i++) {
if (!pages[i])
continue;
memset(page_address(pages[i]), 0, PAGE_CACHE_SIZE);
-- 
2.5.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 0/2] Fix coding style issues and a consistence change.

2015-09-09 Thread Maitesin
Some fixes for coding style issues and consistence in a conditional.

Maitesin (2):
  fs: isofs: Fix a coding style issue and change conditional to make it
consistence
  fs: isofs: Fix several coding style issues

 fs/isofs/compress.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

-- 
2.5.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] fs: isofs: Fix a coding style issue and change conditional to make it consistence

2015-09-07 Thread Maitesin
The coding style issue is the white spaces after and before the brackets in the 
for. The change in the conditional is to make it consistence with the other 
ones in the file. All other conditionals are tested like that.

Signed-off-by: Oscar Forner Martinez 
---
 fs/isofs/compress.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/isofs/compress.c b/fs/isofs/compress.c
index f311bf0..5750830 100644
--- a/fs/isofs/compress.c
+++ b/fs/isofs/compress.c
@@ -66,8 +66,8 @@ static loff_t zisofs_uncompress_block(struct inode *inode, 
loff_t block_start,
return 0;
}
/* Empty block? */
-   if (block_size == 0) {
-   for ( i = 0 ; i < pcount ; i++ ) {
+   if (!block_size) {
+   for (i = 0 ; i < pcount ; i++) {
if (!pages[i])
continue;
memset(page_address(pages[i]), 0, PAGE_CACHE_SIZE);
-- 
2.5.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] fs: isofs: Fix a coding style issue and change conditional to make it consistence

2015-09-07 Thread Maitesin
The coding style issue is the white spaces after and before the brackets in the 
for. The change in the conditional is to make it consistence with the other 
ones in the file. All other conditionals are tested like that.

Signed-off-by: Oscar Forner Martinez 
---
 fs/isofs/compress.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/isofs/compress.c b/fs/isofs/compress.c
index f311bf0..5750830 100644
--- a/fs/isofs/compress.c
+++ b/fs/isofs/compress.c
@@ -66,8 +66,8 @@ static loff_t zisofs_uncompress_block(struct inode *inode, 
loff_t block_start,
return 0;
}
/* Empty block? */
-   if (block_size == 0) {
-   for ( i = 0 ; i < pcount ; i++ ) {
+   if (!block_size) {
+   for (i = 0 ; i < pcount ; i++) {
if (!pages[i])
continue;
memset(page_address(pages[i]), 0, PAGE_CACHE_SIZE);
-- 
2.5.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/