public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/13] DRBD-receiver: Fine-tuning for six function implementations
@ 2016-09-10 20:20 SF Markus Elfring
  2016-09-10 20:22 ` [PATCH 01/13] DRBD-receiver: Use kmalloc_array() in receive_uuids() SF Markus Elfring
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: SF Markus Elfring @ 2016-09-10 20:20 UTC (permalink / raw)
  To: drbd-dev, Lars Ellenberg, Philipp Reisner
  Cc: LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 10 Sep 2016 22:13:22 +0200

Several update suggestions were taken into account
from static source code analysis.

Markus Elfring (13):
  Use kmalloc_array() in receive_uuids()
  Delete an error message for a failed kmalloc_array() call
  Move an assignment in receive_uuids()
  Improve a size determination in drbd_do_features()
  Delete an unnecessary initialisation in receive_sizes()
  Improve a size determination in receive_sizes()
  Delete an error message for a failed kzalloc() call in receive_sizes()
  Move an assignment in receive_sizes()
  Improve determination of sizes in receive_SyncParam()
  Delete error messages for failed resource allocations in receive_SyncParam()
  Improve a size determination in receive_protocol()
  Delete error messages for failed resource allocations in receive_protocol()
  Improve determination of sizes in receive_Barrier()

 drivers/block/drbd/drbd_receiver.c | 45 ++++++++++++++++----------------------
 1 file changed, 19 insertions(+), 26 deletions(-)

-- 
2.10.0

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 01/13] DRBD-receiver: Use kmalloc_array() in receive_uuids()
  2016-09-10 20:20 [PATCH 00/13] DRBD-receiver: Fine-tuning for six function implementations SF Markus Elfring
@ 2016-09-10 20:22 ` SF Markus Elfring
  2016-09-10 20:23 ` [PATCH 02/13] DRBD-receiver: Delete an error message for a failed kmalloc_array() call SF Markus Elfring
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: SF Markus Elfring @ 2016-09-10 20:22 UTC (permalink / raw)
  To: drbd-dev, Lars Ellenberg, Philipp Reisner
  Cc: LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 10 Sep 2016 19:22:57 +0200

* A multiplication for the size determination of a memory allocation
  indicated that an array data structure should be processed.
  Thus use the corresponding function "kmalloc_array".

  This issue was detected by using the Coccinelle software.

* Replace the specification of a data type by a pointer dereference
  to make the corresponding size determination a bit safer according to
  the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/block/drbd/drbd_receiver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index 942384f..3be9fbf 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -4186,7 +4186,7 @@ static int receive_uuids(struct drbd_connection *connection, struct packet_info
 		return config_unknown_volume(connection, pi);
 	device = peer_device->device;
 
-	p_uuid = kmalloc(sizeof(u64)*UI_EXTENDED_SIZE, GFP_NOIO);
+	p_uuid = kmalloc_array(UI_EXTENDED_SIZE, sizeof(*p_uuid), GFP_NOIO);
 	if (!p_uuid) {
 		drbd_err(device, "kmalloc of p_uuid failed\n");
 		return false;
-- 
2.10.0

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 02/13] DRBD-receiver: Delete an error message for a failed kmalloc_array() call
  2016-09-10 20:20 [PATCH 00/13] DRBD-receiver: Fine-tuning for six function implementations SF Markus Elfring
  2016-09-10 20:22 ` [PATCH 01/13] DRBD-receiver: Use kmalloc_array() in receive_uuids() SF Markus Elfring
@ 2016-09-10 20:23 ` SF Markus Elfring
  2016-09-10 20:24 ` [PATCH 03/13] DRBD-receiver: Move an assignment in receive_uuids() SF Markus Elfring
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: SF Markus Elfring @ 2016-09-10 20:23 UTC (permalink / raw)
  To: drbd-dev, Lars Ellenberg, Philipp Reisner
  Cc: LKML, kernel-janitors, Julia Lawall, Wolfram Sang

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 10 Sep 2016 19:26:07 +0200

Omit an extra message for a memory allocation failure in this function.

Link: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/block/drbd/drbd_receiver.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index 3be9fbf..dab3f74 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -4187,10 +4187,8 @@ static int receive_uuids(struct drbd_connection *connection, struct packet_info
 	device = peer_device->device;
 
 	p_uuid = kmalloc_array(UI_EXTENDED_SIZE, sizeof(*p_uuid), GFP_NOIO);
-	if (!p_uuid) {
-		drbd_err(device, "kmalloc of p_uuid failed\n");
+	if (!p_uuid)
 		return false;
-	}
 
 	for (i = UI_CURRENT; i < UI_EXTENDED_SIZE; i++)
 		p_uuid[i] = be64_to_cpu(p->uuid[i]);
-- 
2.10.0

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 03/13] DRBD-receiver: Move an assignment in receive_uuids()
  2016-09-10 20:20 [PATCH 00/13] DRBD-receiver: Fine-tuning for six function implementations SF Markus Elfring
  2016-09-10 20:22 ` [PATCH 01/13] DRBD-receiver: Use kmalloc_array() in receive_uuids() SF Markus Elfring
  2016-09-10 20:23 ` [PATCH 02/13] DRBD-receiver: Delete an error message for a failed kmalloc_array() call SF Markus Elfring
@ 2016-09-10 20:24 ` SF Markus Elfring
  2016-09-10 20:25 ` [PATCH 04/13] DRBD-receiver: Improve a size determination in drbd_do_features() SF Markus Elfring
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: SF Markus Elfring @ 2016-09-10 20:24 UTC (permalink / raw)
  To: drbd-dev, Lars Ellenberg, Philipp Reisner
  Cc: LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 10 Sep 2016 19:37:42 +0200

Move one assignment for the local variable "updated_uuids" so that
its setting will only be performed after corresponding memory
allocations succeeded by this function.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/block/drbd/drbd_receiver.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index dab3f74..5526f6b 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -4179,7 +4179,7 @@ static int receive_uuids(struct drbd_connection *connection, struct packet_info
 	struct drbd_device *device;
 	struct p_uuids *p = pi->data;
 	u64 *p_uuid;
-	int i, updated_uuids = 0;
+	int i, updated_uuids;
 
 	peer_device = conn_peer_device(connection, pi->vnr);
 	if (!peer_device)
@@ -4206,6 +4206,7 @@ static int receive_uuids(struct drbd_connection *connection, struct packet_info
 		return -EIO;
 	}
 
+	updated_uuids = 0;
 	if (get_ldev(device)) {
 		int skip_initial_sync =
 			device->state.conn == C_CONNECTED &&
-- 
2.10.0

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 04/13] DRBD-receiver: Improve a size determination in drbd_do_features()
  2016-09-10 20:20 [PATCH 00/13] DRBD-receiver: Fine-tuning for six function implementations SF Markus Elfring
                   ` (2 preceding siblings ...)
  2016-09-10 20:24 ` [PATCH 03/13] DRBD-receiver: Move an assignment in receive_uuids() SF Markus Elfring
@ 2016-09-10 20:25 ` SF Markus Elfring
  2016-09-10 20:26 ` [PATCH 05/13] DRBD-receiver: Delete an unnecessary initialisation in receive_sizes() SF Markus Elfring
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: SF Markus Elfring @ 2016-09-10 20:25 UTC (permalink / raw)
  To: drbd-dev, Lars Ellenberg, Philipp Reisner
  Cc: LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 10 Sep 2016 19:46:05 +0200

Replace the specification of a data structure by a pointer dereference
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/block/drbd/drbd_receiver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index 5526f6b..b5a3cf0 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -5208,7 +5208,7 @@ static int drbd_do_features(struct drbd_connection *connection)
 {
 	/* ASSERT current == connection->receiver ... */
 	struct p_connection_features *p;
-	const int expect = sizeof(struct p_connection_features);
+	const int expect = sizeof(*p);
 	struct packet_info pi;
 	int err;
 
-- 
2.10.0

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 05/13] DRBD-receiver: Delete an unnecessary initialisation in receive_sizes()
  2016-09-10 20:20 [PATCH 00/13] DRBD-receiver: Fine-tuning for six function implementations SF Markus Elfring
                   ` (3 preceding siblings ...)
  2016-09-10 20:25 ` [PATCH 04/13] DRBD-receiver: Improve a size determination in drbd_do_features() SF Markus Elfring
@ 2016-09-10 20:26 ` SF Markus Elfring
  2016-09-10 20:28 ` [PATCH 06/13] DRBD-receiver: Improve a size determination " SF Markus Elfring
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: SF Markus Elfring @ 2016-09-10 20:26 UTC (permalink / raw)
  To: drbd-dev, Lars Ellenberg, Philipp Reisner
  Cc: LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 10 Sep 2016 20:04:02 +0200

A local variable was assigned a null pointer despite of the detail
that it was immediately reassigned by the following statement.
Thus remove such an unnecessary initialisation.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/block/drbd/drbd_receiver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index b5a3cf0..7666212 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -4083,7 +4083,7 @@ static int receive_sizes(struct drbd_connection *connection, struct packet_info
 		}
 
 		if (my_usize != p_usize) {
-			struct disk_conf *old_disk_conf, *new_disk_conf = NULL;
+			struct disk_conf *old_disk_conf, *new_disk_conf;
 
 			new_disk_conf = kzalloc(sizeof(struct disk_conf), GFP_KERNEL);
 			if (!new_disk_conf) {
-- 
2.10.0

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 06/13] DRBD-receiver: Improve a size determination in receive_sizes()
  2016-09-10 20:20 [PATCH 00/13] DRBD-receiver: Fine-tuning for six function implementations SF Markus Elfring
                   ` (4 preceding siblings ...)
  2016-09-10 20:26 ` [PATCH 05/13] DRBD-receiver: Delete an unnecessary initialisation in receive_sizes() SF Markus Elfring
@ 2016-09-10 20:28 ` SF Markus Elfring
  2016-09-10 20:30 ` [PATCH 07/13] DRBD-receiver: Delete an error message for a failed kzalloc() call " SF Markus Elfring
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: SF Markus Elfring @ 2016-09-10 20:28 UTC (permalink / raw)
  To: drbd-dev, Lars Ellenberg, Philipp Reisner
  Cc: LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 10 Sep 2016 21:45:13 +0200

Replace the specification of a data structure by a pointer dereference
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/block/drbd/drbd_receiver.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index 7666212..64bc316 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -4085,7 +4085,8 @@ static int receive_sizes(struct drbd_connection *connection, struct packet_info
 		if (my_usize != p_usize) {
 			struct disk_conf *old_disk_conf, *new_disk_conf;
 
-			new_disk_conf = kzalloc(sizeof(struct disk_conf), GFP_KERNEL);
+			new_disk_conf = kzalloc(sizeof(*new_disk_conf),
+						GFP_KERNEL);
 			if (!new_disk_conf) {
 				drbd_err(device, "Allocation of new disk_conf failed\n");
 				put_ldev(device);
-- 
2.10.0

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 07/13] DRBD-receiver: Delete an error message for a failed kzalloc() call in receive_sizes()
  2016-09-10 20:20 [PATCH 00/13] DRBD-receiver: Fine-tuning for six function implementations SF Markus Elfring
                   ` (5 preceding siblings ...)
  2016-09-10 20:28 ` [PATCH 06/13] DRBD-receiver: Improve a size determination " SF Markus Elfring
@ 2016-09-10 20:30 ` SF Markus Elfring
  2016-09-10 20:31 ` [PATCH 08/13] DRBD-receiver: Move an assignment " SF Markus Elfring
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: SF Markus Elfring @ 2016-09-10 20:30 UTC (permalink / raw)
  To: drbd-dev, Lars Ellenberg, Philipp Reisner
  Cc: LKML, kernel-janitors, Julia Lawall, Wolfram Sang

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 10 Sep 2016 21:48:21 +0200

Omit an extra message for a memory allocation failure in this function.

Link: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/block/drbd/drbd_receiver.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index 64bc316..6a9c16e 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -4088,7 +4088,6 @@ static int receive_sizes(struct drbd_connection *connection, struct packet_info
 			new_disk_conf = kzalloc(sizeof(*new_disk_conf),
 						GFP_KERNEL);
 			if (!new_disk_conf) {
-				drbd_err(device, "Allocation of new disk_conf failed\n");
 				put_ldev(device);
 				return -ENOMEM;
 			}
-- 
2.10.0

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 08/13] DRBD-receiver: Move an assignment in receive_sizes()
  2016-09-10 20:20 [PATCH 00/13] DRBD-receiver: Fine-tuning for six function implementations SF Markus Elfring
                   ` (6 preceding siblings ...)
  2016-09-10 20:30 ` [PATCH 07/13] DRBD-receiver: Delete an error message for a failed kzalloc() call " SF Markus Elfring
@ 2016-09-10 20:31 ` SF Markus Elfring
  2016-09-10 20:32 ` [PATCH 09/13] DRBD-receiver: Improve determination of sizes in receive_SyncParam() SF Markus Elfring
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: SF Markus Elfring @ 2016-09-10 20:31 UTC (permalink / raw)
  To: drbd-dev, Lars Ellenberg, Philipp Reisner
  Cc: LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 10 Sep 2016 21:50:18 +0200

Move one assignment for the local variable "ldsc" so that its setting
will only be performed after corresponding data processing succeeded
by this function.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/block/drbd/drbd_receiver.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index 6a9c16e..2fe58d1 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -4036,7 +4036,7 @@ static int receive_sizes(struct drbd_connection *connection, struct packet_info
 	struct o_qlim *o = (connection->agreed_features & DRBD_FF_WSAME) ? p->qlim : NULL;
 	enum determine_dev_size dd = DS_UNCHANGED;
 	sector_t p_size, p_usize, p_csize, my_usize;
-	int ldsc = 0; /* local disk size changed */
+	int ldsc; /* local disk size changed */
 	enum dds_flags ddsf;
 
 	peer_device = conn_peer_device(connection, pi->vnr);
@@ -4141,6 +4141,7 @@ static int receive_sizes(struct drbd_connection *connection, struct packet_info
 		drbd_set_my_capacity(device, p_csize ?: p_usize ?: p_size);
 	}
 
+	ldsc = 0;
 	if (get_ldev(device)) {
 		if (device->ldev->known_size != drbd_get_capacity(device->ldev->backing_bdev)) {
 			device->ldev->known_size = drbd_get_capacity(device->ldev->backing_bdev);
-- 
2.10.0

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 09/13] DRBD-receiver: Improve determination of sizes in receive_SyncParam()
  2016-09-10 20:20 [PATCH 00/13] DRBD-receiver: Fine-tuning for six function implementations SF Markus Elfring
                   ` (7 preceding siblings ...)
  2016-09-10 20:31 ` [PATCH 08/13] DRBD-receiver: Move an assignment " SF Markus Elfring
@ 2016-09-10 20:32 ` SF Markus Elfring
  2016-09-10 20:33 ` [PATCH 10/13] DRBD-receiver: Delete error messages for failed resource allocations " SF Markus Elfring
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: SF Markus Elfring @ 2016-09-10 20:32 UTC (permalink / raw)
  To: drbd-dev, Lars Ellenberg, Philipp Reisner
  Cc: LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 10 Sep 2016 21:54:55 +0200

Replace the specification of data structures by pointer dereferences
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/block/drbd/drbd_receiver.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index 2fe58d1..6fbd968 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -3859,7 +3859,7 @@ static int receive_SyncParam(struct drbd_connection *connection, struct packet_i
 	mutex_lock(&connection->resource->conf_update);
 	old_net_conf = peer_device->connection->net_conf;
 	if (get_ldev(device)) {
-		new_disk_conf = kzalloc(sizeof(struct disk_conf), GFP_KERNEL);
+		new_disk_conf = kzalloc(sizeof(*new_disk_conf), GFP_KERNEL);
 		if (!new_disk_conf) {
 			put_ldev(device);
 			mutex_unlock(&connection->resource->conf_update);
@@ -3946,7 +3946,8 @@ static int receive_SyncParam(struct drbd_connection *connection, struct packet_i
 		}
 
 		if (verify_tfm || csums_tfm) {
-			new_net_conf = kzalloc(sizeof(struct net_conf), GFP_KERNEL);
+			new_net_conf = kzalloc(sizeof(*new_net_conf),
+					       GFP_KERNEL);
 			if (!new_net_conf) {
 				drbd_err(device, "Allocation of new net_conf failed\n");
 				goto disconnect;
-- 
2.10.0

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 10/13] DRBD-receiver: Delete error messages for failed resource allocations in receive_SyncParam()
  2016-09-10 20:20 [PATCH 00/13] DRBD-receiver: Fine-tuning for six function implementations SF Markus Elfring
                   ` (8 preceding siblings ...)
  2016-09-10 20:32 ` [PATCH 09/13] DRBD-receiver: Improve determination of sizes in receive_SyncParam() SF Markus Elfring
@ 2016-09-10 20:33 ` SF Markus Elfring
  2016-09-10 20:34 ` [PATCH 11/13] DRBD-receiver: Improve a size determination in receive_protocol() SF Markus Elfring
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: SF Markus Elfring @ 2016-09-10 20:33 UTC (permalink / raw)
  To: drbd-dev, Lars Ellenberg, Philipp Reisner
  Cc: LKML, kernel-janitors, Julia Lawall, Wolfram Sang

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 10 Sep 2016 22:00:10 +0200

Omit three messages for memory allocation failures in this function.

Link: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/block/drbd/drbd_receiver.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index 6fbd968..3e1315a 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -3863,7 +3863,6 @@ static int receive_SyncParam(struct drbd_connection *connection, struct packet_i
 		if (!new_disk_conf) {
 			put_ldev(device);
 			mutex_unlock(&connection->resource->conf_update);
-			drbd_err(device, "Allocation of new disk_conf failed\n");
 			return -ENOMEM;
 		}
 
@@ -3938,7 +3937,6 @@ static int receive_SyncParam(struct drbd_connection *connection, struct packet_i
 			if (fifo_size != device->rs_plan_s->size) {
 				new_plan = fifo_alloc(fifo_size);
 				if (!new_plan) {
-					drbd_err(device, "kmalloc of fifo_buffer failed");
 					put_ldev(device);
 					goto disconnect;
 				}
@@ -3948,10 +3946,8 @@ static int receive_SyncParam(struct drbd_connection *connection, struct packet_i
 		if (verify_tfm || csums_tfm) {
 			new_net_conf = kzalloc(sizeof(*new_net_conf),
 					       GFP_KERNEL);
-			if (!new_net_conf) {
-				drbd_err(device, "Allocation of new net_conf failed\n");
+			if (!new_net_conf)
 				goto disconnect;
-			}
 
 			*new_net_conf = *old_net_conf;
 
-- 
2.10.0

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 11/13] DRBD-receiver: Improve a size determination in receive_protocol()
  2016-09-10 20:20 [PATCH 00/13] DRBD-receiver: Fine-tuning for six function implementations SF Markus Elfring
                   ` (9 preceding siblings ...)
  2016-09-10 20:33 ` [PATCH 10/13] DRBD-receiver: Delete error messages for failed resource allocations " SF Markus Elfring
@ 2016-09-10 20:34 ` SF Markus Elfring
  2016-09-10 20:35 ` [PATCH 12/13] DRBD-receiver: Delete error messages for failed resource allocations " SF Markus Elfring
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: SF Markus Elfring @ 2016-09-10 20:34 UTC (permalink / raw)
  To: drbd-dev, Lars Ellenberg, Philipp Reisner
  Cc: LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 10 Sep 2016 22:02:11 +0200

Replace the specification of a data structure by a pointer dereference
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/block/drbd/drbd_receiver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index 3e1315a..bbccdb8 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -3697,7 +3697,7 @@ static int receive_protocol(struct drbd_connection *connection, struct packet_in
 		}
 	}
 
-	new_net_conf = kmalloc(sizeof(struct net_conf), GFP_KERNEL);
+	new_net_conf = kmalloc(sizeof(*new_net_conf), GFP_KERNEL);
 	if (!new_net_conf) {
 		drbd_err(connection, "Allocation of new net_conf failed\n");
 		goto disconnect;
-- 
2.10.0

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 12/13] DRBD-receiver: Delete error messages for failed resource allocations in receive_protocol()
  2016-09-10 20:20 [PATCH 00/13] DRBD-receiver: Fine-tuning for six function implementations SF Markus Elfring
                   ` (10 preceding siblings ...)
  2016-09-10 20:34 ` [PATCH 11/13] DRBD-receiver: Improve a size determination in receive_protocol() SF Markus Elfring
@ 2016-09-10 20:35 ` SF Markus Elfring
  2016-09-10 20:36 ` [PATCH 13/13] DRBD-receiver: Improve determination of sizes in receive_Barrier() SF Markus Elfring
  2017-08-06 10:18 ` [PATCH 00/13] DRBD-receiver: Fine-tuning for six function implementations SF Markus Elfring
  13 siblings, 0 replies; 15+ messages in thread
From: SF Markus Elfring @ 2016-09-10 20:35 UTC (permalink / raw)
  To: drbd-dev, Lars Ellenberg, Philipp Reisner
  Cc: LKML, kernel-janitors, Julia Lawall, Wolfram Sang

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 10 Sep 2016 22:04:08 +0200

Omit two messages for memory allocation failures in this function.

Link: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/block/drbd/drbd_receiver.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index bbccdb8..e4da335 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -3691,17 +3691,13 @@ static int receive_protocol(struct drbd_connection *connection, struct packet_in
 		hash_size = crypto_ahash_digestsize(peer_integrity_tfm);
 		int_dig_in = kmalloc(hash_size, GFP_KERNEL);
 		int_dig_vv = kmalloc(hash_size, GFP_KERNEL);
-		if (!(int_dig_in && int_dig_vv)) {
-			drbd_err(connection, "Allocation of buffers for data integrity checking failed\n");
+		if (!(int_dig_in && int_dig_vv))
 			goto disconnect;
-		}
 	}
 
 	new_net_conf = kmalloc(sizeof(*new_net_conf), GFP_KERNEL);
-	if (!new_net_conf) {
-		drbd_err(connection, "Allocation of new net_conf failed\n");
+	if (!new_net_conf)
 		goto disconnect;
-	}
 
 	mutex_lock(&connection->data.mutex);
 	mutex_lock(&connection->resource->conf_update);
-- 
2.10.0

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 13/13] DRBD-receiver: Improve determination of sizes in receive_Barrier()
  2016-09-10 20:20 [PATCH 00/13] DRBD-receiver: Fine-tuning for six function implementations SF Markus Elfring
                   ` (11 preceding siblings ...)
  2016-09-10 20:35 ` [PATCH 12/13] DRBD-receiver: Delete error messages for failed resource allocations " SF Markus Elfring
@ 2016-09-10 20:36 ` SF Markus Elfring
  2017-08-06 10:18 ` [PATCH 00/13] DRBD-receiver: Fine-tuning for six function implementations SF Markus Elfring
  13 siblings, 0 replies; 15+ messages in thread
From: SF Markus Elfring @ 2016-09-10 20:36 UTC (permalink / raw)
  To: drbd-dev, Lars Ellenberg, Philipp Reisner
  Cc: LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 10 Sep 2016 22:06:21 +0200

Replace the specification of data structures by pointer dereferences
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/block/drbd/drbd_receiver.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index e4da335..32ac4a9 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -1747,7 +1747,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
 
 		/* receiver context, in the writeout path of the other node.
 		 * avoid potential distributed deadlock */
-		epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
+		epoch = kmalloc(sizeof(*epoch), GFP_NOIO);
 		if (epoch)
 			break;
 		else
@@ -1760,7 +1760,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
 		drbd_flush(connection);
 
 		if (atomic_read(&connection->current_epoch->epoch_size)) {
-			epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
+			epoch = kmalloc(sizeof(*epoch), GFP_NOIO);
 			if (epoch)
 				break;
 		}
-- 
2.10.0

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH 00/13] DRBD-receiver: Fine-tuning for six function implementations
  2016-09-10 20:20 [PATCH 00/13] DRBD-receiver: Fine-tuning for six function implementations SF Markus Elfring
                   ` (12 preceding siblings ...)
  2016-09-10 20:36 ` [PATCH 13/13] DRBD-receiver: Improve determination of sizes in receive_Barrier() SF Markus Elfring
@ 2017-08-06 10:18 ` SF Markus Elfring
  13 siblings, 0 replies; 15+ messages in thread
From: SF Markus Elfring @ 2017-08-06 10:18 UTC (permalink / raw)
  To: drbd-dev, Lars Ellenberg, Philipp Reisner; +Cc: LKML, kernel-janitors

> Date: Sat, 10 Sep 2016 22:13:22 +0200
> 
> Several update suggestions were taken into account
> from static source code analysis.
> 
> Markus Elfring (13):
>   Use kmalloc_array() in receive_uuids()
>   Delete an error message for a failed kmalloc_array() call
>   Move an assignment in receive_uuids()
>   Improve a size determination in drbd_do_features()
>   Delete an unnecessary initialisation in receive_sizes()
>   Improve a size determination in receive_sizes()
>   Delete an error message for a failed kzalloc() call in receive_sizes()
>   Move an assignment in receive_sizes()
>   Improve determination of sizes in receive_SyncParam()
>   Delete error messages for failed resource allocations in receive_SyncParam()
>   Improve a size determination in receive_protocol()
>   Delete error messages for failed resource allocations in receive_protocol()
>   Improve determination of sizes in receive_Barrier()
> 
>  drivers/block/drbd/drbd_receiver.c | 45 ++++++++++++++++----------------------
>  1 file changed, 19 insertions(+), 26 deletions(-)

Would you like to take another look at change possibilities
for this software module?

Regards,
Markus

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2017-08-06 10:18 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-10 20:20 [PATCH 00/13] DRBD-receiver: Fine-tuning for six function implementations SF Markus Elfring
2016-09-10 20:22 ` [PATCH 01/13] DRBD-receiver: Use kmalloc_array() in receive_uuids() SF Markus Elfring
2016-09-10 20:23 ` [PATCH 02/13] DRBD-receiver: Delete an error message for a failed kmalloc_array() call SF Markus Elfring
2016-09-10 20:24 ` [PATCH 03/13] DRBD-receiver: Move an assignment in receive_uuids() SF Markus Elfring
2016-09-10 20:25 ` [PATCH 04/13] DRBD-receiver: Improve a size determination in drbd_do_features() SF Markus Elfring
2016-09-10 20:26 ` [PATCH 05/13] DRBD-receiver: Delete an unnecessary initialisation in receive_sizes() SF Markus Elfring
2016-09-10 20:28 ` [PATCH 06/13] DRBD-receiver: Improve a size determination " SF Markus Elfring
2016-09-10 20:30 ` [PATCH 07/13] DRBD-receiver: Delete an error message for a failed kzalloc() call " SF Markus Elfring
2016-09-10 20:31 ` [PATCH 08/13] DRBD-receiver: Move an assignment " SF Markus Elfring
2016-09-10 20:32 ` [PATCH 09/13] DRBD-receiver: Improve determination of sizes in receive_SyncParam() SF Markus Elfring
2016-09-10 20:33 ` [PATCH 10/13] DRBD-receiver: Delete error messages for failed resource allocations " SF Markus Elfring
2016-09-10 20:34 ` [PATCH 11/13] DRBD-receiver: Improve a size determination in receive_protocol() SF Markus Elfring
2016-09-10 20:35 ` [PATCH 12/13] DRBD-receiver: Delete error messages for failed resource allocations " SF Markus Elfring
2016-09-10 20:36 ` [PATCH 13/13] DRBD-receiver: Improve determination of sizes in receive_Barrier() SF Markus Elfring
2017-08-06 10:18 ` [PATCH 00/13] DRBD-receiver: Fine-tuning for six function implementations SF Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox