Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754042AbbKBQsI (ORCPT ); Mon, 2 Nov 2015 11:48:08 -0500 Received: from mail-bn1bon0116.outbound.protection.outlook.com ([157.56.111.116]:31712 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752735AbbKBQsF (ORCPT ); Mon, 2 Nov 2015 11:48:05 -0500 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; freescale.mail.onmicrosoft.com; dkim=none (message not signed) header.d=none;freescale.mail.onmicrosoft.com; dmarc=none action=none header.from=freescale.com; From: Madalin Bucur To: CC: , , , , , , , , , , , Madalin Bucur Subject: [net-next v4 1/8] devres: add devm_alloc_percpu() Date: Mon, 2 Nov 2015 19:31:33 +0200 Message-ID: <1446485500-9782-2-git-send-email-madalin.bucur@freescale.com> X-Mailer: git-send-email 1.5.6.5 In-Reply-To: <1446485500-9782-1-git-send-email-madalin.bucur@freescale.com> References: <1446485500-9782-1-git-send-email-madalin.bucur@freescale.com> Reply-To: X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11OLC012;1:WJ/QFr/HDNILeMB/YGcpLdxa0S4KzMUcXvPiuoxNsWO1+Xa3GkDlAszC23SP/5sMnequutOtQ9q8edn1L9CYlAo9LkjKa9HHtuX+P/NyS93N9Vsh7WSeeEs+Dej3xhimu+BZBoqA4prkwYN0OpEZ43huPaaGV7syKxcojzr4SQ3dv++0qUIj9MUWXUVyXOSkL8obgchKHAmYoTJsAhdZJLUWEs4AOicGF3ZRmMAdUcS4jShUqjhEIM/789Y7AbTkoDfz+hlKdDdOH/fmqdWRVDz28wuFOqpeb6UfeauDTBt0Czz7nXh5yhy1Cj1qfhln3ah0TL5FRgKMIxl4rV6SKWqITY5Tu3kxj/Zlsl0Rrf6W2U+LcZJiiol5epVL35UVfS86j5P66IYaouyLaz1T/w== X-Forefront-Antispam-Report: CIP:192.88.168.50;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(2980300002)(1109001)(1110001)(339900001)(199003)(189002)(85426001)(5001960100002)(107886002)(5003940100001)(110136002)(33646002)(48376002)(77096005)(81156007)(97736004)(49486002)(2950100001)(189998001)(11100500001)(50986999)(6806005)(76176999)(36756003)(47776003)(50226001)(53806999)(87936001)(50466002)(104016004)(5008740100001)(86362001)(43066003)(19580405001)(5007970100001)(229853001)(19580395003)(2351001)(4001430100002)(106466001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM2PR03MB512;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;A:1;MX:1;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;DM2PR03MB512;2:pnrPvh7aVtirhHOQQ9BpUkT/G2VP3V22FtCI/XLE6hjTrPCnKEwRVEYzk1JbM5+7NIrpWy8ahKAUfZpW+6CNDnw9giFc6zn87LavJ/RSO70keKZjXlzWiPaGwdQgxVJR2nXTUST+oFEfNsapfeVQGdmy1YgS4RxP7W3fTscSZNA=;3:SDE/aaRCPT2iGTiEtoE6BeuVmJGp+JSV6QTLeoQbTaFuUYitUtTUA4+zSBRkY/vlQisEKj+vxiVbc7mBZUEzt8NI+zKug99krdlMD2ZjV+JoJgDP7mMTS3rcfMJKmFb/TNHGvJiABECnROGXHDftXGmtkYePUpaLixW2pfaqu2JbPWyffVEMx8IuHRe63oSdRM8pqlbIXiKlFXulBFRAPbcsY2vEygQRaU4QmR50e6Y=;25:fDzJhtoHaPffNx/Emg/OP+KSIlgpqKfZam1pcRlQqPIvEGlDxiyqOHBEOSWkfYcfV6qVPnVsaTF3oG9b08Rvr6U3IS7Lbt64yhmSlNR7ua6unWhLCG4pnB2zuFDmv1bpmbWEv3PgXOxyUn1IEGbUNntqlFlfJT3HoUuLFM7wpITV6T37K+e0N826andcdY971xs47AUNIDWiGA3nROXMJrVjttLH5xx8IBiINzo46M0mShhmXFVQvlMbQuuNTLTgj6jia18Vx0FNGLik7/tUGw== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR03MB512; X-Microsoft-Exchange-Diagnostics: 1;DM2PR03MB512;20:J851BrpHU6LqCSQF8negryWeNSlZMi4nrg69OqNKolNd1FfquESWSODdXME2tUQbUiDG46C9EKaxAfzMJjJDCflP457g+eJxfPnwgKcZEO70TKMXQr+FLVby2oal2sgIRI0rtqsvEl64RBe+VS5TwJsYfRgykumGhwF0lbpkX4pxgvZnbyNmXYvvLPgP3Hs1eGybOBHH+Zxd2R4SmgEa27d23FIkov0XLb84J8CFGSps18zZNFtUc07HyIyLtRLUnNcT80Eot5irpE5F5+vJ8r9JWZVgHVcEDncll2M61RDtULO2TCi2sQUyxwCKnEvD0i5t1HGcNv1JXs2VIAi8NMa2SP6RlJOgruqzO3nKeyQ=;4:0ng3MQBFIDiRhBUiWATVRO4YVNPzqJi2WKjtWeZDeP5BxwKyDZGgK0m+FW0Q9JunIq86EaP0tuMCdfgZg3aGOW3hIesyz59MwMtTX/w7ag8n8/YsCsUM61nnaYSVBxk1uxlkAaMZEluAHxr4LbXWgwbv5Yr6MloxWVGSFFCOEUetsJfbWd7I4BcZWgj827QHXTalUnRBk2dDCvdG57FzxXoz8UvU11xNbhColKVDSx0995OUIwj1rMXyWRALHy1sowOOpVMCry3SrbhO/NIXqpPi+AjdeN3N5VT/D8HNiG4+juDQc4qVfSQCAb0noMPwco0yfQuKE9BhYUY6pNfXBxW9YoKwGECK+R1MV0d0LP92cUMrB22+Y06bFV8IaH3z X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(101931422205132); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(520078)(5005006)(8121501046)(10201501046)(3002001);SRVR:DM2PR03MB512;BCL:0;PCL:0;RULEID:;SRVR:DM2PR03MB512; X-Forefront-PRVS: 0748FF9A04 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DM2PR03MB512;23:+rzGf6EsHq2zQSluZWeDcH5PiewEKPEamjTsWfI2pg?= =?us-ascii?Q?exk0G9opMH3YMtqTXsNxnAQkAUwHLDjt3Rkc3PnWg5kT8KnTrZ9xSRf5SRlW?= =?us-ascii?Q?Lp4VGCYJOtwk2cQGVdvfH3lnWKSp7JHxDiefoLFjz1gnJmFWTEvFwWRzWkBR?= =?us-ascii?Q?BoKklkaXp4Xocq/1BBU2Z+TsfuMstSqiko2HMVRBCFrLw4FRUhDgomoB0HvY?= =?us-ascii?Q?HzzUZoyrYvcL00kG1m528JrGCX1xa+X035KnB5uYc45tAEobwiN+VFFiBhnR?= =?us-ascii?Q?zc2H7Tsz7d/xHX+FEqml1ZyD4n+gDrJS7TEZU2+b+HQYShruF8voJr9M8SOt?= =?us-ascii?Q?80Fsw92vhjyeOXosrQkPWzq/E733zubJjXLthdxoY4XCV7voqekipeblJfq8?= =?us-ascii?Q?VisbxZ/8wndSq+Uwb5tcsgWo7giSiWgeZT14RG8xISJV1RiGWtRoFVJr/RKS?= =?us-ascii?Q?c3VfcHaPgNAFcDeH9nKa0lZtOkUpzYN2bxZDP+sY89rHZuT3+IbDNAo7Ylwn?= =?us-ascii?Q?t2YHrm/nb6x3T8mrVlywBE/Nh0bjJN+JkdecgGR94a/LuXFGB4n5Q0Ywb7BG?= =?us-ascii?Q?2q5TCZm4PIisJLnJ8dkX0GebmcBvhHG2BH5WfqhcC+4FADoJz+LLTfXY3M+f?= =?us-ascii?Q?r7bSp/vLi8DGewwVnbQZU7q3m70X0oKz44CE/+4rbeHocrdjN5TGFgW2mnVe?= =?us-ascii?Q?5BP0UPdKp2waO+yxnBQpF0MioEZRsrrh4HjLAtfKfOYClJxR1i62S/L9d4tF?= =?us-ascii?Q?Jl4bNIrmVWDIXebxrzkSeo7BJug8PIHcSq57zdcQLQuCn0BK8YFLETF3JnWp?= =?us-ascii?Q?xL/F+pexYqxnTvhSSRw0WCNnDLQlPPjUOyJdSVuId69PcPJVIq3XdGcbtuJ4?= =?us-ascii?Q?o4PIIUmwSwoeEAG+yFjMPBW8k8HC9RtAwizgYQfdIavBvBtnQFiARJzitXZL?= =?us-ascii?Q?pALul73Xj6B4mlOvE11E9EtwnnW57JsJXIbgWGI21le3n4012oLYolhEXlIa?= =?us-ascii?Q?btiu/zmO9zlDCCHP+xDF1CBfWqH90PGi/+IwNrM3qg8PU7c8TxZyVUvXDHlU?= =?us-ascii?Q?RrqNGmnaM5QBkT01QkTWkRhAzOzGkg0G/RqQaNY0fecYVc5xIoj4wem3ZPQf?= =?us-ascii?Q?YJ+v0U3H8=3D?= X-Microsoft-Exchange-Diagnostics: 1;DM2PR03MB512;5:+47zTp/Fw/Vb7GSqLZGIfF5hJdaRrlKTOTtxSl/p4RRQLNf/f0hV2lxaWqQntm5ylLyC3REztTNfKIpDaugMSxw1/Dtt25T5ZVTNYWYoLp+v+9quTJqOS98IKPZ9nLzhL+12NeJcEa3i0v5ONUw8xw==;24:zAnSnlyzotexNlYqoiwsa30/9fk8Hspgq1FCWLambDIJWqm6YBhsQCzCu6ljUF+HDtJh/aFTYcBlDhdS8gFDBnK/FF+1tMK7ZYEKOGIqA8k=;20:jtxw5ytbfdXcf3Au5exlyVWVx3rpakd21pHz53RH8UzaHMuXx9Xk4SjWUfm7TeHk/6oc6KP3CkPi3KE86k64vg== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Nov 2015 16:33:54.1358 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d;Ip=[192.88.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR03MB512 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4385 Lines: 144 Introduce managed counterparts for alloc_percpu() and free_percpu(). Add devm_alloc_percpu() and devm_free_percpu() into the managed interfaces list. Signed-off-by: Madalin Bucur Tested-by: Madalin-Cristian Bucur --- Documentation/driver-model/devres.txt | 4 +++ drivers/base/devres.c | 64 +++++++++++++++++++++++++++++++++++ include/linux/device.h | 19 +++++++++++ 3 files changed, 87 insertions(+) diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt index 831a536..595fd1b 100644 --- a/Documentation/driver-model/devres.txt +++ b/Documentation/driver-model/devres.txt @@ -312,6 +312,10 @@ MEM devm_kvasprintf() devm_kzalloc() +PER-CPU MEM + devm_alloc_percpu() + devm_free_percpu() + PCI pcim_enable_device() : after success, all PCI ops become managed pcim_pin_device() : keep PCI device enabled after release diff --git a/drivers/base/devres.c b/drivers/base/devres.c index 8754646..6c314cc 100644 --- a/drivers/base/devres.c +++ b/drivers/base/devres.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "base.h" @@ -984,3 +985,66 @@ void devm_free_pages(struct device *dev, unsigned long addr) &devres)); } EXPORT_SYMBOL_GPL(devm_free_pages); + +static void devm_percpu_release(struct device *dev, void *pdata) +{ + void __percpu *p; + + p = *(void __percpu **)pdata; + free_percpu(p); +} + +static int devm_percpu_match(struct device *dev, void *data, void *p) +{ + struct devres *devr = container_of(data, struct devres, data); + + return *(void **)devr->data == p; +} + +/** + * __devm_alloc_percpu - Resource-managed alloc_percpu + * @dev: Device to allocate per-cpu memory for + * @size: Size of per-cpu memory to allocate + * @align: Alignement of per-cpu memory to allocate + * + * Managed alloc_percpu. Per-cpu memory allocated with this function is + * automatically freed on driver detach. + * + * RETURNS: + * Pointer to allocated memory on success, NULL on failure. + */ +void __percpu *__devm_alloc_percpu(struct device *dev, size_t size, + size_t align) +{ + void *p; + void __percpu *pcpu; + + pcpu = __alloc_percpu(size, align); + if (!pcpu) + return NULL; + + p = devres_alloc(devm_percpu_release, sizeof(void *), GFP_KERNEL); + if (!p) + return NULL; + + *(void __percpu **)p = pcpu; + + devres_add(dev, p); + + return pcpu; +} +EXPORT_SYMBOL_GPL(__devm_alloc_percpu); + +/** + * devm_free_percpu - Resource-managed free_percpu + * @dev: Device this memory belongs to + * @pdata: Per-cpu memory to free + * + * Free memory allocated with devm_alloc_percpu(). + */ +void devm_free_percpu(struct device *dev, void __percpu *pdata) +{ + WARN_ON(devres_destroy(dev, devm_percpu_release, devm_percpu_match, + (void *)pdata)); +} +EXPORT_SYMBOL_GPL(devm_free_percpu); diff --git a/include/linux/device.h b/include/linux/device.h index 5d7bc63..b563cc5 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -673,6 +673,25 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res); int devm_add_action(struct device *dev, void (*action)(void *), void *data); void devm_remove_action(struct device *dev, void (*action)(void *), void *data); +/** + * devm_alloc_percpu - Resource-managed alloc_percpu + * @dev: Device to allocate per-cpu memory for + * @type: Type to allocate per-cpu memory for + * + * Managed alloc_percpu. Per-cpu memory allocated with this function is + * automatically freed on driver detach. + * + * RETURNS: + * Pointer to allocated memory on success, NULL on failure. + */ +#define devm_alloc_percpu(dev, type) \ + (typeof(type) __percpu *)__devm_alloc_percpu(dev, sizeof(type), \ + __alignof__(type)) + +void __percpu *__devm_alloc_percpu(struct device *dev, size_t size, + size_t align); +void devm_free_percpu(struct device *dev, void __percpu *pdata); + struct device_dma_parameters { /* * a low level driver may set these to teach IOMMU code about -- 1.7.11.7 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/