From patchwork Sat Sep 12 01:37:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinglong Mee X-Patchwork-Id: 7165781 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 204B49F314 for ; Sat, 12 Sep 2015 01:37:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2ABDC20738 for ; Sat, 12 Sep 2015 01:37:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 261F520726 for ; Sat, 12 Sep 2015 01:37:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752100AbbILBhc (ORCPT ); Fri, 11 Sep 2015 21:37:32 -0400 Received: from mail-pa0-f42.google.com ([209.85.220.42]:34112 "EHLO mail-pa0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753922AbbILBhb (ORCPT ); Fri, 11 Sep 2015 21:37:31 -0400 Received: by padhy16 with SMTP id hy16so89348429pad.1 for ; Fri, 11 Sep 2015 18:37:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-type:content-transfer-encoding; bh=Ys5WhRI4/wBA2e/78LhzpCpDdl8h62aQDfQfmLARCnM=; b=YyNeB3jRqGZVPmQ6NT5rAiQVLxt0UrMKt/qpO3bFL3b+D6+WeQg0fVD62v/fEglQFR y2TACnlZocLLDdUZEPKCKmP5U4Qg/UjQXqfJ1Up3iwsAuG/xTzdpd6xUwH5D7/bLeCT2 jhsuO5OicSLN02T74dsQqWw8ygrcn+9CExmnhK/M8Y/KJg8I52WUE/3yUToIT06fPX4O EJ84ph3EfiDE4UHAypSTpF371XI3w48Xx5pf7QokiGMqshpnBV0Be1HUSDHgHb6lO6Uc XIQpdXJRtXHdU/NpWcOuuiS+1ek/oVvjamdgWjMmwu3DrN8crZqqFeCa8g0Oo8TMYQnS /vRA== X-Received: by 10.68.247.226 with SMTP id yh2mr4115254pbc.12.1442021851481; Fri, 11 Sep 2015 18:37:31 -0700 (PDT) Received: from [192.168.99.16] ([104.143.41.79]) by smtp.googlemail.com with ESMTPSA id xf6sm2661521pbc.70.2015.09.11.18.37.27 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Sep 2015 18:37:30 -0700 (PDT) Subject: [PATCH v2] Sunrpc: Supports hexadecimal number for sysctl files of sunrpc debug To: "J. Bruce Fields" References: <55F17A7E.50406@gmail.com> <20150911212320.GG11677@fieldses.org> <55F38130.7020802@gmail.com> Cc: Trond Myklebust , "linux-nfs@vger.kernel.org" , kinglongmee@gmail.com From: Kinglong Mee Message-ID: <55F381CE.4070600@gmail.com> Date: Sat, 12 Sep 2015 09:37:18 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <55F38130.7020802@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The sunrpc debug sysctl files only accept decimal number right now. But all the XXXDBUG_XXX macros are defined as hexadecimal. It is not easy to set or check an separate flag. This patch let those files support accepting hexadecimal number, (decimal number is also supported). Also, display it as hexadecimal. v2, Remove duplicate parsing of '0x...', just using simple_strtol(tmpbuf, &s, 0) Fix a bug of isspace() checking after parsing Signed-off-by: Kinglong Mee --- net/sunrpc/sysctl.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/net/sunrpc/sysctl.c b/net/sunrpc/sysctl.c index 887f018..c88d9bc 100644 --- a/net/sunrpc/sysctl.c +++ b/net/sunrpc/sysctl.c @@ -76,7 +76,7 @@ static int proc_dodebug(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) { - char tmpbuf[20], c, *s; + char tmpbuf[20], c, *s = NULL; char __user *p; unsigned int value; size_t left, len; @@ -103,23 +103,24 @@ proc_dodebug(struct ctl_table *table, int write, return -EFAULT; tmpbuf[left] = '\0'; - for (s = tmpbuf, value = 0; '0' <= *s && *s <= '9'; s++, left--) - value = 10 * value + (*s - '0'); - if (*s && !isspace(*s)) - return -EINVAL; - while (left && isspace(*s)) - left--, s++; + value = simple_strtol(tmpbuf, &s, 0); + if (s) { + left -= (s - tmpbuf); + if (left && !isspace(*s)) + return -EINVAL; + while (left && isspace(*s)) + left--, s++; + } else + left = 0; *(unsigned int *) table->data = value; /* Display the RPC tasks on writing to rpc_debug */ if (strcmp(table->procname, "rpc_debug") == 0) rpc_show_tasks(&init_net); } else { - if (!access_ok(VERIFY_WRITE, buffer, left)) - return -EFAULT; - len = sprintf(tmpbuf, "%d", *(unsigned int *) table->data); + len = sprintf(tmpbuf, "0x%04x", *(unsigned int *) table->data); if (len > left) len = left; - if (__copy_to_user(buffer, tmpbuf, len)) + if (copy_to_user(buffer, tmpbuf, len)) return -EFAULT; if ((left -= len) > 0) { if (put_user('\n', (char __user *)buffer + len))