Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1241383imj; Thu, 14 Feb 2019 03:31:21 -0800 (PST) X-Google-Smtp-Source: AHgI3IaLhmxJ1qxFt5vc2hb6xFBB27cTV8N5cVDAw0xcUvEk58t5YnKdHpGgv7BnXQwPkPOfvW8q X-Received: by 2002:a17:902:2468:: with SMTP id m37mr3655489plg.314.1550143881496; Thu, 14 Feb 2019 03:31:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550143881; cv=none; d=google.com; s=arc-20160816; b=oyI58Edfp1RfLR2z18IVp/5IupiiX8QcMhd3XWgxdewhZc7eDEDNN8dE0J0O9jQySC LiFkbL+R6dZE5UoTlOFO5hBi5H7Nm1GlLwKXm8ge9j8kYvPUTxZi6+/j9IZVoR6UopO7 EqejNpkAno0V66Q2G+NcIYCqjKBX4L9pdoSfimXPJfuZXmskG33/cLb7D/hzBU5ocV/R IGzcN2Pqd3rsCtA+nQD6nDc0/bpkK+7yDfx3eglaVhvUNxYaEr6IUa6Qy5+aumLwOH6v ceK6n8xuiRlg3kJAj4rfLEJlkW7rdqBKPC199VPwh8CsS9N9w3H6GR9MI7uKjqj7y+KF Vuyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=cMGyrsw5hd2KNvH2kSLymXW1QVKvmNJ5zB7WLee/2fE=; b=J6fOY15NY18Y/7EhSJiE9OHMPBpmBeCZarxioRyGbsMLMv2RkPDw2dPOAyE1SWsJgG BRoscfN/Jj/dhlegXLWaFqzxGVa/LtrXBtppaoFjnbke33tl7C3FzMnBRIRQi8RxQpOB XtiJZ7B4yH0jFyiINJHt4AUhQ9maqi8313q/Nuhe+oOTXG/skZOX6AA9MnrEDrQHB4vI DJ818o9vaVC12ejDJsQYwkWj+xhaVWRi0Nm/da6tQOa99TTNxl5LbyBrSdD5DtZX58M4 rz9ZXflGZxfnLdkOjLRxW/I47JoVjCqDR6Z2boomJ0bAQUlovZ9q284R9MyrQqRi0ZcJ FQ6Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ce8si1046756plb.395.2019.02.14.03.31.05; Thu, 14 Feb 2019 03:31:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405974AbfBNHEq (ORCPT + 99 others); Thu, 14 Feb 2019 02:04:46 -0500 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:26126 "EHLO mail2-relais-roc.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389635AbfBNHEq (ORCPT ); Thu, 14 Feb 2019 02:04:46 -0500 X-IronPort-AV: E=Sophos;i="5.58,367,1544482800"; d="scan'208";a="369343814" Received: from abo-58-107-68.mrs.modulonet.fr (HELO hadrien) ([85.68.107.58]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Feb 2019 08:04:43 +0100 Date: Thu, 14 Feb 2019 08:04:43 +0100 (CET) From: Julia Lawall X-X-Sender: jll@hadrien To: Dan Carpenter cc: Jan Harkes , coda@cs.cmu.edu, codalist@telemann.coda.cs.cmu.edu, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [PATCH] fs/coda: get rid of CODA_ALLOC() In-Reply-To: <20190214065848.GB21768@kadam> Message-ID: References: <20190214065848.GB21768@kadam> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 14 Feb 2019, Dan Carpenter wrote: > These days we have kvzalloc() so we can delete CODA_ALLOC(). Maybe it would be better to get rid fo CODA_FREE as well? julia > > 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 > --- > 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 c5234c21b539..49d44a485c9a 100644 > --- a/fs/coda/psdev.c > +++ b/fs/coda/psdev.c > @@ -124,7 +124,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 1175a1722411..203f029bcdc3 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; > -- > 2.17.1 > >