From 099c0c9a642569edfe672eeb983876b0e6662a75 Mon Sep 17 00:00:00 2001 From: Prakash Gupta Date: Tue, 23 Jul 2019 16:46:41 +0530 Subject: [PATCH] mm: cma: make writeable CMA debugfs optional Make writeable CMA debugfs optional. This will allow exposing readonly CMA debugfs entries for stats. Change-Id: I35cbaa11df5a1d8bb4a2496fcc1b6166ce64abf0 Signed-off-by: Prakash Gupta Signed-off-by: Isaac J. Manjarres --- mm/Kconfig | 9 +++++++++ mm/cma_debug.c | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/mm/Kconfig b/mm/Kconfig index 22e7911403bd..0372bea0ca4c 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -499,6 +499,15 @@ config CMA_DEBUGFS help Turns on the DebugFS interface for CMA. +config CMA_ALLOW_WRITE_DEBUGFS + depends on CMA_DEBUGFS + bool "Allow CMA debugfs write" + help + Say 'y' here to allow the CMA debugfs write. + CMA debugfs write could be risky as it allows + cma allocation, so it is not recommended to + enable this option on any production device. + config CMA_AREAS int "Maximum count of the CMA areas" depends on CMA diff --git a/mm/cma_debug.c b/mm/cma_debug.c index bc9a7d681b7a..42ad17b64001 100644 --- a/mm/cma_debug.c +++ b/mm/cma_debug.c @@ -74,6 +74,7 @@ static int cma_maxchunk_get(void *data, u64 *val) } DEFINE_SIMPLE_ATTRIBUTE(cma_maxchunk_fops, cma_maxchunk_get, NULL, "%llu\n"); +#ifdef CONFIG_CMA_ALLOW_WRITE_DEBUGFS static void cma_add_to_cma_mem_list(struct cma *cma, struct cma_mem *mem) { spin_lock(&cma->mem_head_lock); @@ -132,8 +133,13 @@ static int cma_free_write(void *data, u64 val) return cma_free_mem(cma, pages); } +#else +#define cma_free_write NULL +#endif + DEFINE_SIMPLE_ATTRIBUTE(cma_free_fops, NULL, cma_free_write, "%llu\n"); +#ifdef CONFIG_CMA_ALLOW_WRITE_DEBUGFS static int cma_alloc_mem(struct cma *cma, int count) { struct cma_mem *mem; @@ -164,6 +170,10 @@ static int cma_alloc_write(void *data, u64 val) return cma_alloc_mem(cma, pages); } +#else +#define cma_alloc_write NULL +#endif + DEFINE_SIMPLE_ATTRIBUTE(cma_alloc_fops, NULL, cma_alloc_write, "%llu\n"); static void cma_debugfs_add_one(struct cma *cma, struct dentry *root_dentry)