Subject: Re: [PATCH net-next v2 01/11] devlink: Add health buffer support

From: Jiri Pirko <[email-masked]>
Date: Sun, 20 Jan 2019 11:03:52 +0100

Thu, Jan 17, 2019 at 10:59:10PM CET, [email-masked] wrote:

[...]

>+static void
>+devlink_health_buffers_destroy(struct devlink_health_buffer **buffers_list,
>+			       u64 size);

Avoid fwd declarations.

>+
>+static struct devlink_health_buffer **
>+devlink_health_buffers_create(u64 size)
>+{
>+	struct devlink_health_buffer **buffers_list;
>+	u64 num_of_buffers = DEVLINK_HEALTH_SIZE_TO_BUFFERS(size);
>+	u64 i;
>+
>+	buffers_list = kcalloc(num_of_buffers,
>+			       sizeof(struct devlink_health_buffer *),
>+			       GFP_KERNEL);
>+	if (!buffers_list)
>+		return NULL;
>+
>+	for (i = 0; i < num_of_buffers; i++) {
>+		struct devlink_health_buffer *buffer;
>+		void *data;
>+
>+		buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
>+		data = kzalloc(DEVLINK_HEALTH_BUFFER_SIZE, GFP_KERNEL);
>+		if (!buffer || !data) {
>+			kfree(buffer);
>+			kfree(data);
>+			goto buffers_cleanup;
>+		}
>+		buffers_list[i] = buffer;
>+		buffer->data = data;
>+	}
>+	devlink_health_buffers_reset(buffers_list, num_of_buffers);
>+
>+	return buffers_list;
>+
>+buffers_cleanup:
>+	devlink_health_buffers_destroy(buffers_list, --i);

Just do for-kfree here.

>+	kfree(buffers_list);
>+	return NULL;
>+}
>+
>+static void
>+devlink_health_buffers_destroy(struct devlink_health_buffer **buffers_list,
>+			       u64 num_of_buffers)
>+{
>+	u64 i;
>+
>+	for (i = 0; i < num_of_buffers; i++) {
>+		kfree(buffers_list[i]->data);
>+		kfree(buffers_list[i]);
>+	}
>+}
>+

[...]