From patchwork Wed Mar 20 16:45:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Harkes X-Patchwork-Id: 10862281 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8BB2C1708 for ; Wed, 20 Mar 2019 17:28:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 658E029E2A for ; Wed, 20 Mar 2019 17:28:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A25B29E3E; Wed, 20 Mar 2019 17:28:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF07E29E2A for ; Wed, 20 Mar 2019 17:28:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727196AbfCTR23 (ORCPT ); Wed, 20 Mar 2019 13:28:29 -0400 Received: from hurricane.elijah.cs.cmu.edu ([128.2.209.191]:46720 "EHLO hurricane.elijah.cs.cmu.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727140AbfCTR21 (ORCPT ); Wed, 20 Mar 2019 13:28:27 -0400 Received: from jaharkes by hurricane.elijah.cs.cmu.edu with local (Exim 4.92) (envelope-from ) id 1h6eLV-0006mg-Lp; Wed, 20 Mar 2019 12:45:41 -0400 From: Jan Harkes To: Andrew Morton Cc: Jan Harkes , linux-fsdevel@vger.kernel.org, Dan Carpenter Subject: [PATCH 12/22] coda: get rid of CODA_ALLOC() Date: Wed, 20 Mar 2019 12:45:31 -0400 Message-Id: <87e5ca875156942a148d921a78886b291dd7c4f1.1553098576.git.jaharkes@cs.cmu.edu> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Dan Carpenter These days we have kvzalloc() so we can delete CODA_ALLOC(). I made a couple related changes in coda_psdev_write(). First, I added some error handling to avoid a NULL dereference if the allocation failed. Second, I used kvmalloc() instead of kvzalloc() because we copy over the memory on the next line so there is no need to zero it first. Signed-off-by: Dan Carpenter Signed-off-by: Jan Harkes --- fs/coda/coda_linux.h | 10 ---------- fs/coda/psdev.c | 6 +++++- fs/coda/upcall.c | 4 ++-- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/fs/coda/coda_linux.h b/fs/coda/coda_linux.h index 126155cadfa9..1ea9521e79d7 100644 --- a/fs/coda/coda_linux.h +++ b/fs/coda/coda_linux.h @@ -63,16 +63,6 @@ unsigned short coda_flags_to_cflags(unsigned short); void coda_sysctl_init(void); void coda_sysctl_clean(void); -#define CODA_ALLOC(ptr, cast, size) do { \ - if (size < PAGE_SIZE) \ - ptr = kzalloc((unsigned long) size, GFP_KERNEL); \ - else \ - ptr = (cast)vzalloc((unsigned long) size); \ - if (!ptr) \ - pr_warn("kernel malloc returns 0 at %s:%d\n", __FILE__, __LINE__); \ -} while (0) - - #define CODA_FREE(ptr, size) kvfree((ptr)) /* inode to cnode access functions */ diff --git a/fs/coda/psdev.c b/fs/coda/psdev.c index 7e9ee614ec57..e90ac440fa29 100644 --- a/fs/coda/psdev.c +++ b/fs/coda/psdev.c @@ -127,7 +127,11 @@ static ssize_t coda_psdev_write(struct file *file, const char __user *buf, hdr.opcode, hdr.unique); nbytes = size; } - CODA_ALLOC(dcbuf, union outputArgs *, nbytes); + dcbuf = kvmalloc(nbytes, GFP_KERNEL); + if (!dcbuf) { + retval = -ENOMEM; + goto out; + } if (copy_from_user(dcbuf, buf, nbytes)) { CODA_FREE(dcbuf, nbytes); retval = -EFAULT; diff --git a/fs/coda/upcall.c b/fs/coda/upcall.c index cf1e662681a5..b6ac5fc98189 100644 --- a/fs/coda/upcall.c +++ b/fs/coda/upcall.c @@ -46,7 +46,7 @@ static void *alloc_upcall(int opcode, int size) { union inputArgs *inp; - CODA_ALLOC(inp, union inputArgs *, size); + inp = kvzalloc(size, GFP_KERNEL); if (!inp) return ERR_PTR(-ENOMEM); @@ -743,7 +743,7 @@ static int coda_upcall(struct venus_comm *vcp, sig_req = kmalloc(sizeof(struct upc_req), GFP_KERNEL); if (!sig_req) goto exit; - CODA_ALLOC((sig_req->uc_data), char *, sizeof(struct coda_in_hdr)); + sig_req->uc_data = kvzalloc(sizeof(struct coda_in_hdr), GFP_KERNEL); if (!sig_req->uc_data) { kfree(sig_req); goto exit;