From patchwork Fri Jan 29 14:51:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaehyun Lim X-Patchwork-Id: 8164001 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4C975BEEE5 for ; Fri, 29 Jan 2016 14:51:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 54D732038E for ; Fri, 29 Jan 2016 14:51:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5CF7A20382 for ; Fri, 29 Jan 2016 14:51:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756440AbcA2Ovr (ORCPT ); Fri, 29 Jan 2016 09:51:47 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:36622 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756418AbcA2Ovl (ORCPT ); Fri, 29 Jan 2016 09:51:41 -0500 Received: by mail-pf0-f194.google.com with SMTP id n128so3868138pfn.3 for ; Fri, 29 Jan 2016 06:51:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=BG+FdHZtM2DWB4wiNpRZyECExuXwk/DW7D8NVE2sxCo=; b=eIZFeBV3iNZTSRZmNF3APCYIfJFVdlAIZbdDtaPObw3ZHuoPvWDHSxqR2+C9aJdpUL C5ITb6sd/zonWsBBBhm41FECf1VmS8RjaBF5IlwLsTMT+COUIKSwNKS2Cuguc8DSAlZX ogr+7nF55i4aEDo4GeScCqq6FekCy2A/gen/1IRlJM5WGgCBj+Z8hL8mWTnep1BzgCL+ tLDMlpinJ6Ji3TqADuqBlYYuHgR69DT8y42uWwUG3Y4eqyL4oUUysfTs4ncE9eQiQ0HL y3jcaISsus8xUEbwb7l6WisyT30FlhoGUk8/VmZkN5vax1SWQYyFDW+VpQTLuhqPTCY8 SsLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=BG+FdHZtM2DWB4wiNpRZyECExuXwk/DW7D8NVE2sxCo=; b=bikmUf1UFxDzd5kGTqdKalSWmsYrsdnBAqTx3y1Nv/IrEMK1lvJta0DoIFdh1mS4vC mIoyuCZCn7r2Jbwwh23EHYvl4MNIjUQ4gTo/ecJzZUg7uBeyr6Z3Qs4EeOBD9lFgqCFC ersnChKN6e9f4mRWU8HDXZb32uL+3N0YBoHqoGOtRro+VZBvaQJZb85u3I/CmggBNMkf 9lQ2ltAubd3a4iBodgxJDwGYMtHV38JDt1UPrlkgDPpjHTuuLJoNIKUqLfuvadT6QdAu mu0OJ92RsfUeH0v/9rE5c4kl8JhSCFvEDMkEU6sDKbr40uU2RodEQj15L/Ympt9I9TcX zQLQ== X-Gm-Message-State: AG10YORdgp99PngEo51LXw19ldaTqVT93f7ISvejMU/iP8Wpz28RwGPw2TlE7+bz1DgkMQ== X-Received: by 10.98.8.14 with SMTP id c14mr13861771pfd.42.1454079100880; Fri, 29 Jan 2016 06:51:40 -0800 (PST) Received: from localhost.localdomain ([218.233.16.2]) by smtp.gmail.com with ESMTPSA id dz12sm24230692pac.2.2016.01.29.06.51.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 29 Jan 2016 06:51:40 -0800 (PST) From: Chaehyun Lim To: gregkh@linuxfoundation.org Cc: johnny.kim@atmel.com, austin.shin@atmel.com, chris.park@atmel.com, tony.cho@atmel.com, glen.lee@atmel.com, leo.kim@atmel.com, linux-wireless@vger.kernel.org, devel@driverdev.osuosl.org, Chaehyun Lim Subject: [PATCH 1/2] staging: wilc1000: wilc_msgqueue: use standard struct list_head Date: Fri, 29 Jan 2016 23:51:32 +0900 Message-Id: <1454079093-7011-1-git-send-email-chaehyun.lim@gmail.com> X-Mailer: git-send-email 2.7.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch uses standard struct list_head in struct message and message_queue instead of custom linked list. Signed-off-by: Chaehyun Lim --- drivers/staging/wilc1000/wilc_msgqueue.c | 32 ++++++++++++-------------------- drivers/staging/wilc1000/wilc_msgqueue.h | 5 +++-- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/drivers/staging/wilc1000/wilc_msgqueue.c b/drivers/staging/wilc1000/wilc_msgqueue.c index 4493ca9..f57e4ec 100644 --- a/drivers/staging/wilc1000/wilc_msgqueue.c +++ b/drivers/staging/wilc1000/wilc_msgqueue.c @@ -15,7 +15,7 @@ int wilc_mq_create(struct message_queue *mq) { spin_lock_init(&mq->lock); sema_init(&mq->sem, 0); - mq->msg_list = NULL; + INIT_LIST_HEAD(&mq->msg_list); mq->recv_count = 0; mq->exiting = false; return 0; @@ -29,6 +29,8 @@ int wilc_mq_create(struct message_queue *mq) */ int wilc_mq_destroy(struct message_queue *mq) { + struct message *msg; + mq->exiting = true; /* Release any waiting receiver thread. */ @@ -37,11 +39,10 @@ int wilc_mq_destroy(struct message_queue *mq) mq->recv_count--; } - while (mq->msg_list) { - struct message *msg = mq->msg_list->next; - - kfree(mq->msg_list); - mq->msg_list = msg; + while (!list_empty(&mq->msg_list)) { + msg = list_first_entry(&mq->msg_list, struct message, list); + list_del(&msg->list); + kfree(msg->buf); } return 0; @@ -75,7 +76,7 @@ int wilc_mq_send(struct message_queue *mq, return -ENOMEM; new_msg->len = send_buf_size; - new_msg->next = NULL; + INIT_LIST_HEAD(&new_msg->list); new_msg->buf = kmemdup(send_buf, send_buf_size, GFP_ATOMIC); if (!new_msg->buf) { kfree(new_msg); @@ -85,16 +86,7 @@ int wilc_mq_send(struct message_queue *mq, spin_lock_irqsave(&mq->lock, flags); /* add it to the message queue */ - if (!mq->msg_list) { - mq->msg_list = new_msg; - } else { - struct message *tail_msg = mq->msg_list; - - while (tail_msg->next) - tail_msg = tail_msg->next; - - tail_msg->next = new_msg; - } + list_add_tail(&new_msg->list, &mq->msg_list); spin_unlock_irqrestore(&mq->lock, flags); @@ -132,13 +124,13 @@ int wilc_mq_recv(struct message_queue *mq, down(&mq->sem); spin_lock_irqsave(&mq->lock, flags); - msg = mq->msg_list; - if (!msg) { + if (list_empty(&mq->msg_list)) { spin_unlock_irqrestore(&mq->lock, flags); PRINT_ER("msg is null\n"); return -EFAULT; } /* check buffer size */ + msg = list_first_entry(&mq->msg_list, struct message, list); if (recv_buf_size < msg->len) { spin_unlock_irqrestore(&mq->lock, flags); up(&mq->sem); @@ -151,7 +143,7 @@ int wilc_mq_recv(struct message_queue *mq, memcpy(recv_buf, msg->buf, msg->len); *recv_len = msg->len; - mq->msg_list = msg->next; + list_del(&msg->list); kfree(msg->buf); kfree(msg); diff --git a/drivers/staging/wilc1000/wilc_msgqueue.h b/drivers/staging/wilc1000/wilc_msgqueue.h index ddd09843..846a484 100644 --- a/drivers/staging/wilc1000/wilc_msgqueue.h +++ b/drivers/staging/wilc1000/wilc_msgqueue.h @@ -2,11 +2,12 @@ #define __WILC_MSG_QUEUE_H__ #include +#include struct message { void *buf; u32 len; - struct message *next; + struct list_head list; }; struct message_queue { @@ -14,7 +15,7 @@ struct message_queue { spinlock_t lock; bool exiting; u32 recv_count; - struct message *msg_list; + struct list_head msg_list; }; int wilc_mq_create(struct message_queue *mq);