From patchwork Thu Oct 10 23:06:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 282494 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-pd0-x23c.google.com (mail-pd0-x23c.google.com [IPv6:2607:f8b0:400e:c02::23c]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 989062C00CA for ; Fri, 11 Oct 2013 10:06:08 +1100 (EST) Received: by mail-pd0-f188.google.com with SMTP id w10sf553196pde.5 for ; Thu, 10 Oct 2013 16:06:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :reply-to:precedence:mailing-list:list-id:list-post:list-help :list-archive:sender:list-subscribe:list-unsubscribe:content-type; bh=997PnwbuT/CqdfOAiyU4Vc6sZb0fWLnlnRqsxJr+Oug=; b=IEqBPaACt0nMxQ2eGTAb0D0HM+mQwnrSncFT/MPOhjI5V+hNXDDPCxlVyEfIUHp6IB Om8bGctDVhwpWgI5E51vCVi9FAlBpRZ/B7gBDt7ps5aovnROc5C7DYUodgewtrnuFD90 N0NNnZYdCgk516luD1603UmOgSZPtmkZ50Y9RSeKf+8L5uFWN9nqhe1HHJ6R4lgCqQMW nkpDgUzPiQFHqMOC6AoHNVu3c7YnKVpyA9rVFT9MROY1uqHzFWJViWpTXlyHIFGGyzRW L/dMgeiIqlmHnxUWYYcbFXxqCXGRJhzoWVxRa2CAiMPeYBTCI9frNuWOWTmi6+tMn6sI ucbg== X-Received: by 10.49.86.71 with SMTP id n7mr109591qez.22.1381446365596; Thu, 10 Oct 2013 16:06:05 -0700 (PDT) X-BeenThere: rtc-linux@googlegroups.com Received: by 10.49.35.244 with SMTP id l20ls1252149qej.98.gmail; Thu, 10 Oct 2013 16:06:05 -0700 (PDT) X-Received: by 10.224.125.72 with SMTP id x8mr21865738qar.5.1381446365025; Thu, 10 Oct 2013 16:06:05 -0700 (PDT) Received: from mail.linuxfoundation.org (mail.linuxfoundation.org. [140.211.169.12]) by gmr-mx.google.com with ESMTP id ax8si708622pbd.0.1969.12.31.16.00.00; Thu, 10 Oct 2013 16:06:04 -0700 (PDT) Received-SPF: pass (google.com: domain of akpm@linux-foundation.org designates 140.211.169.12 as permitted sender) client-ip=140.211.169.12; Received: from akpm3.mtv.corp.google.com (unknown [216.239.45.95]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 6768E98E; Thu, 10 Oct 2013 23:06:04 +0000 (UTC) Date: Thu, 10 Oct 2013 16:06:03 -0700 From: Andrew Morton To: Joe Perches Cc: "sangjung.woo" , Alessandro Rubini , Russell King , rtc-linux@googlegroups.com, linux-kernel@vger.kernel.org, Tejun Heo , Greg KH Subject: [rtc-linux] Re: [PATCH] rtc: pl030: Use devm_kzalloc() instead of kmalloc() Message-Id: <20131010160603.1489fe054c2bdc0a0eb9460f@linux-foundation.org> In-Reply-To: <1381294767.2040.5.camel@joe-AO722> References: <1381291240-23727-1-git-send-email-sangjung.woo@samsung.com> <1381291649.2040.1.camel@joe-AO722> <5254DD64.4090205@samsung.com> <1381294767.2040.5.camel@joe-AO722> X-Mailer: Sylpheed 3.2.0beta5 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 X-Original-Sender: akpm@linux-foundation.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of akpm@linux-foundation.org designates 140.211.169.12 as permitted sender) smtp.mail=akpm@linux-foundation.org Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: Sender: rtc-linux@googlegroups.com List-Subscribe: , List-Unsubscribe: , On Tue, 08 Oct 2013 21:59:27 -0700 Joe Perches wrote: > I was a bit surprised to find there isn't a devm_kmalloc. Yes, the unconditional memset is silly. Especially when the function has a handy gfp_t and could be passed __GFP_ZERO. The comment says "managed kzalloc/kfree for device drivers, no kmalloc, always use kzalloc". There's no explanation for this - it looks like some ideological thing. --- a/drivers/base/devres.c~a +++ a/drivers/base/devres.c @@ -91,7 +91,8 @@ static __always_inline struct devres * a if (unlikely(!dr)) return NULL; - memset(dr, 0, tot_size); + if (gfp & __GFP_ZERO) + memset(dr, 0, tot_size); INIT_LIST_HEAD(&dr->node.entry); dr->node.release = release; return dr; @@ -770,7 +771,7 @@ static int devm_kzalloc_match(struct dev * RETURNS: * Pointer to allocated memory on success, NULL on failure. */ -void * devm_kzalloc(struct device *dev, size_t size, gfp_t gfp) +static void *__devm_kzalloc(struct device *dev, size_t size, gfp_t gfp) { struct devres *dr; @@ -783,8 +784,19 @@ void * devm_kzalloc(struct device *dev, devres_add(dev, dr->data); return dr->data; } + +void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp) +{ + return __devm_kzalloc(dev, size, gfp | __GFP_ZERO); +} EXPORT_SYMBOL_GPL(devm_kzalloc); +void *devm_kmalloc(struct device *dev, size_t size, gfp_t gfp) +{ + return __devm_kzalloc(dev, size, gfp); +} +EXPORT_SYMBOL_GPL(devm_kmalloc); + /** * devm_kfree - Resource-managed kfree * @dev: Device this memory belongs to --- a/include/linux/device.h~a +++ a/include/linux/device.h @@ -602,8 +602,9 @@ extern void devres_close_group(struct de extern void devres_remove_group(struct device *dev, void *id); extern int devres_release_group(struct device *dev, void *id); -/* managed kzalloc/kfree for device drivers, no kmalloc, always use kzalloc */ +/* managed kmalloc/kzalloc/kfree for device drivers */ extern void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp); +extern void *devm_kmalloc(struct device *dev, size_t size, gfp_t gfp); extern void devm_kfree(struct device *dev, void *p); void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res);