From patchwork Fri Oct 9 17:11:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 54729 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by patches.linaro.org (Postfix) with ESMTPS id 7076822FFC for ; Fri, 9 Oct 2015 17:11:33 +0000 (UTC) Received: by wisv5 with SMTP id v5sf32392157wis.0 for ; Fri, 09 Oct 2015 10:11:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=LFgtLylMXMn+4JpZ+XkBk5OuUCaPJpnH+TZLIFoljXQ=; b=gL4IMb1HnApm1ndqVl+4MLVKUjsKEIL0G5JqSabLHUoCTVwYYsLPpKQOpUSOGCSXzA N7EZY7yH2TKhJu0SSk8OV77biXfFoSn3QQ/ZJ2t99YRpyHeK+9t4t7EKd9bOpMJV/gQV ApBs3NRSHVGrmeHQOlpH5dXLlvH+BRXQ/0ougaJVIBLHTrUc+0acpk6VABNc4xeJHX3K ibZONl7qCg5q1vRHUnEuyzR6ewaUBkSl8xXIl1dC99211OvTk8z8epX1ntlBQhlp76WM pcGfKV747mb8/T0Lce0hIpDZKs/B0AThl1nOdaCZhrrjwNSwr1ognlvgwASgx3HflSBV tQwA== X-Gm-Message-State: ALoCoQkEjA8iaAw9F97E6HcTEVhuMvlEQgyXrP2szBBz7EalOWNru0JO+IJdVnq94junyazXriiE X-Received: by 10.112.130.41 with SMTP id ob9mr2797784lbb.17.1444410692706; Fri, 09 Oct 2015 10:11:32 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.24.104 with SMTP id o101ls171842lfi.48.gmail; Fri, 09 Oct 2015 10:11:32 -0700 (PDT) X-Received: by 10.112.205.69 with SMTP id le5mr7143707lbc.89.1444410692576; Fri, 09 Oct 2015 10:11:32 -0700 (PDT) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id ja1si1905363lbc.40.2015.10.09.10.11.32 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Oct 2015 10:11:32 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by lbbwt4 with SMTP id wt4so87660749lbb.1 for ; Fri, 09 Oct 2015 10:11:32 -0700 (PDT) X-Received: by 10.25.86.213 with SMTP id k204mr4654179lfb.36.1444410692434; Fri, 09 Oct 2015 10:11:32 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp109703lbq; Fri, 9 Oct 2015 10:11:29 -0700 (PDT) X-Received: by 10.69.17.195 with SMTP id gg3mr16237841pbd.166.1444410689711; Fri, 09 Oct 2015 10:11:29 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ch2si3939708pad.82.2015.10.09.10.11.27; Fri, 09 Oct 2015 10:11:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758539AbbJIRL0 (ORCPT + 12 others); Fri, 9 Oct 2015 13:11:26 -0400 Received: from mail-pa0-f47.google.com ([209.85.220.47]:35043 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750987AbbJIRLZ (ORCPT ); Fri, 9 Oct 2015 13:11:25 -0400 Received: by pabve7 with SMTP id ve7so33214067pab.2 for ; Fri, 09 Oct 2015 10:11:25 -0700 (PDT) X-Received: by 10.68.57.238 with SMTP id l14mr16592255pbq.150.1444410684826; Fri, 09 Oct 2015 10:11:24 -0700 (PDT) Received: from localhost ([122.171.124.154]) by smtp.gmail.com with ESMTPSA id kl11sm3465554pbd.67.2015.10.09.10.11.22 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 09 Oct 2015 10:11:23 -0700 (PDT) From: Viresh Kumar To: Greg Kroah-Hartman Cc: linaro-kernel@lists.linaro.org, Rafael Wysocki , linux-kernel@vger.kernel.org, arnd@arndb.de, sboyd@codeaurora.org, linux-pm@vger.kernel.org, linux@arm.linux.org.uk, stern@rowland.harvard.edu, Viresh Kumar Subject: [PATCH V2] debugfs: Add debugfs_create_ulong() Date: Fri, 9 Oct 2015 22:41:16 +0530 Message-Id: <69e3888403d23de9aadf3792be3c0bdce57495b0.1444410517.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.4.0 In-Reply-To: <3a48d2bb4320bba82f91354d7165c300ef8108bd.1444402709.git.viresh.kumar@linaro.org> References: <3a48d2bb4320bba82f91354d7165c300ef8108bd.1444402709.git.viresh.kumar@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Add debugfs_create_ulong() for the users of type 'unsigned long'. These will be 32 bits long on a 32 bit machine and 64 bits long on a 64 bit machine. Signed-off-by: Viresh Kumar --- V1->V2: - Fix missing debugfs_create_xlong() routine, was left in the repository. fs/debugfs/file.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/debugfs.h | 4 +++ 2 files changed, 76 insertions(+) diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index b70c20fae502..129d19b72fd4 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c @@ -251,6 +251,60 @@ struct dentry *debugfs_create_u64(const char *name, umode_t mode, } EXPORT_SYMBOL_GPL(debugfs_create_u64); +static int debugfs_ulong_set(void *data, u64 val) +{ + *(unsigned long *)data = val; + return 0; +} + +static int debugfs_ulong_get(void *data, u64 *val) +{ + *val = *(unsigned long *)data; + return 0; +} +DEFINE_SIMPLE_ATTRIBUTE(fops_ulong, debugfs_ulong_get, debugfs_ulong_set, "%llu\n"); +DEFINE_SIMPLE_ATTRIBUTE(fops_ulong_ro, debugfs_ulong_get, NULL, "%llu\n"); +DEFINE_SIMPLE_ATTRIBUTE(fops_ulong_wo, NULL, debugfs_ulong_set, "%llu\n"); + +/** + * debugfs_create_ulong - create a debugfs file that is used to read and write + * an unsigned long value. + * @name: a pointer to a string containing the name of the file to create. + * @mode: the permission that the file should have + * @parent: a pointer to the parent dentry for this file. This should be a + * directory dentry if set. If this parameter is %NULL, then the + * file will be created in the root of the debugfs filesystem. + * @value: a pointer to the variable that the file should read to and write + * from. + * + * This function creates a file in debugfs with the given name that + * contains the value of the variable @value. If the @mode variable is so + * set, it can be read from, and written to. + * + * This function will return a pointer to a dentry if it succeeds. This + * pointer must be passed to the debugfs_remove() function when the file is + * to be removed (no automatic cleanup happens if your module is unloaded, + * you are responsible here.) If an error occurs, %NULL will be returned. + * + * If debugfs is not enabled in the kernel, the value -%ENODEV will be + * returned. It is not wise to check for this value, but rather, check for + * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling + * code. + */ +struct dentry *debugfs_create_ulong(const char *name, umode_t mode, + struct dentry *parent, unsigned long *value) +{ + /* if there are no write bits set, make read only */ + if (!(mode & S_IWUGO)) + return debugfs_create_file(name, mode, parent, value, &fops_ulong_ro); + /* if there are no read bits set, make write only */ + if (!(mode & S_IRUGO)) + return debugfs_create_file(name, mode, parent, value, &fops_ulong_wo); + + return debugfs_create_file(name, mode, parent, value, &fops_ulong); +} +EXPORT_SYMBOL_GPL(debugfs_create_ulong); + DEFINE_SIMPLE_ATTRIBUTE(fops_x8, debugfs_u8_get, debugfs_u8_set, "0x%02llx\n"); DEFINE_SIMPLE_ATTRIBUTE(fops_x8_ro, debugfs_u8_get, NULL, "0x%02llx\n"); DEFINE_SIMPLE_ATTRIBUTE(fops_x8_wo, NULL, debugfs_u8_set, "0x%02llx\n"); @@ -264,6 +318,7 @@ DEFINE_SIMPLE_ATTRIBUTE(fops_x32_ro, debugfs_u32_get, NULL, "0x%08llx\n"); DEFINE_SIMPLE_ATTRIBUTE(fops_x32_wo, NULL, debugfs_u32_set, "0x%08llx\n"); DEFINE_SIMPLE_ATTRIBUTE(fops_x64, debugfs_u64_get, debugfs_u64_set, "0x%016llx\n"); +DEFINE_SIMPLE_ATTRIBUTE(fops_xlong, debugfs_ulong_get, debugfs_ulong_set, "0x%016llx\n"); /* * debugfs_create_x{8,16,32,64} - create a debugfs file that is used to read and write an unsigned {8,16,32,64}-bit value @@ -362,6 +417,23 @@ struct dentry *debugfs_create_x64(const char *name, umode_t mode, } EXPORT_SYMBOL_GPL(debugfs_create_x64); +/** + * debugfs_create_xlong - create a debugfs file that is used to read and write an unsigned long value + * @name: a pointer to a string containing the name of the file to create. + * @mode: the permission that the file should have + * @parent: a pointer to the parent dentry for this file. This should be a + * directory dentry if set. If this parameter is %NULL, then the + * file will be created in the root of the debugfs filesystem. + * @value: a pointer to the variable that the file should read to and write + * from. + */ +struct dentry *debugfs_create_xlong(const char *name, umode_t mode, + struct dentry *parent, unsigned long *value) +{ + return debugfs_create_file(name, mode, parent, value, &fops_xlong); +} +EXPORT_SYMBOL_GPL(debugfs_create_xlong); + static int debugfs_size_t_set(void *data, u64 val) { diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h index 8321fe3058d6..60b150248b54 100644 --- a/include/linux/debugfs.h +++ b/include/linux/debugfs.h @@ -79,6 +79,8 @@ struct dentry *debugfs_create_u32(const char *name, umode_t mode, struct dentry *parent, u32 *value); struct dentry *debugfs_create_u64(const char *name, umode_t mode, struct dentry *parent, u64 *value); +struct dentry *debugfs_create_ulong(const char *name, umode_t mode, + struct dentry *parent, unsigned long *value); struct dentry *debugfs_create_x8(const char *name, umode_t mode, struct dentry *parent, u8 *value); struct dentry *debugfs_create_x16(const char *name, umode_t mode, @@ -87,6 +89,8 @@ struct dentry *debugfs_create_x32(const char *name, umode_t mode, struct dentry *parent, u32 *value); struct dentry *debugfs_create_x64(const char *name, umode_t mode, struct dentry *parent, u64 *value); +struct dentry *debugfs_create_xlong(const char *name, umode_t mode, + struct dentry *parent, unsigned long *value); struct dentry *debugfs_create_size_t(const char *name, umode_t mode, struct dentry *parent, size_t *value); struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode,