From patchwork Thu Apr 24 07:25:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 342132 X-Patchwork-Delegate: benh@kernel.crashing.org Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 710741413E2 for ; Thu, 24 Apr 2014 17:36:22 +1000 (EST) Received: from mail-pa0-f44.google.com (mail-pa0-f44.google.com [209.85.220.44]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 91818141471 for ; Thu, 24 Apr 2014 17:25:56 +1000 (EST) Received: by mail-pa0-f44.google.com with SMTP id bj1so1627703pad.17 for ; Thu, 24 Apr 2014 00:25:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jms.id.au; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Boz9PIngmyBy7+bxKCi+bTLR+9W2fdwN5Fk9Zb+1Lmk=; b=GPWGqEikwhk4YxuylJSEYuqEBgNqBLwhT0dmKTsooyqUrtmlop884yIgbCwreTJ7k9 4Mr1z2SU251jXyTQuhqGxJKi+noXLqyJId9sXfgynSmdv6j+cSMVz51mTy4mFw2ZsyJq vcXSX4VHSkO3X1+gayZn+HaSB/J3/EYx5WP3U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Boz9PIngmyBy7+bxKCi+bTLR+9W2fdwN5Fk9Zb+1Lmk=; b=jhABq9SMQtsVRGEOACYoWRPEJQwBihujQ9kLpDDaua5/ACyBQj7jRgM6KGTsJ9EIzs RM9FcqWhYJ03c7Lw+sMlK4sD7QnvVs0tE48c0M8TGPw/TxamAweQSGBS7WzT9kD28Et+ wNMJMlJZDqheDoqTa4pOy+QtOKVcL7MsWUGx8Rd2lXzZp3lQaaQnjbG6SrbtXmG0HHwO NrZWgyPxUmyOEEZX1RyHadgNrC9Bt0BjX+yyxIwJk12WBCreLzJuFsjAK8u5q+g8yg48 xOmPNv1oWOaZ7TBSrqvl+4SdHRfR1zi4eUEgjo1IFELjazGSocWpQPilwpL4sEofBmYQ qRNg== X-Gm-Message-State: ALoCoQkkULpg9Ne0wCtcmn/bubh4a0WG//R5J7zyCsV6VdBU9ypvL7WWsOllAA5xQMvWW5FqjUf/ X-Received: by 10.68.222.105 with SMTP id ql9mr601492pbc.4.1398324353500; Thu, 24 Apr 2014 00:25:53 -0700 (PDT) Received: from icarus.au.ibm.com (ppp118-210-54-94.lns20.adl2.internode.on.net. [118.210.54.94]) by mx.google.com with ESMTPSA id qx11sm16230192pab.35.2014.04.24.00.25.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 24 Apr 2014 00:25:53 -0700 (PDT) From: Joel Stanley To: benh@kernel.crashing.org Subject: [PATCH 1/5] powerpc/powernv: Fix sysparam sysfs error handling Date: Thu, 24 Apr 2014 16:55:33 +0930 Message-Id: <1398324337-896-2-git-send-email-joel@jms.id.au> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1398324337-896-1-git-send-email-joel@jms.id.au> References: <1398324337-896-1-git-send-email-joel@jms.id.au> Cc: neelegup@linux.vnet.ibm.com, linuxppc-dev@lists.ozlabs.org, paulus@samba.org X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" When a sysparam query in OPAL returned a negative value (error code), sysfs would spew out a decent chunk of memory; almost 64K more than expected. This was traced to a sign/unsigned mix up in the OPAL sysparam sysfs code at sys_param_show. The return value of sys_param_show is a ssize_t, calculated using return ret ? ret : attr->param_size; Alan Modra explains: "attr->param_size" is an unsigned int, "ret" an int, so the overall expression has type unsigned int. Result is that ret is cast to unsigned int before being cast to ssize_t. Instead of using the ternary operator, set ret to the param_size if an error is not detected. The same bug exists in the sysfs write callback; this patch fixes it in the same way. A note on debugging this next time: on my system gcc will warn about this if compiled with -Wsign-compare, which is not enabled by -Wall, only -Wextra. Signed-off-by: Joel Stanley --- arch/powerpc/platforms/powernv/opal-sysparam.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/platforms/powernv/opal-sysparam.c b/arch/powerpc/platforms/powernv/opal-sysparam.c index 0bd249a..cdaf145 100644 --- a/arch/powerpc/platforms/powernv/opal-sysparam.c +++ b/arch/powerpc/platforms/powernv/opal-sysparam.c @@ -121,9 +121,10 @@ static ssize_t sys_param_show(struct kobject *kobj, memcpy(buf, param_data_buf, attr->param_size); + ret = attr->param_size; out: mutex_unlock(&opal_sysparam_mutex); - return ret ? ret : attr->param_size; + return ret; } static ssize_t sys_param_store(struct kobject *kobj, @@ -138,7 +139,9 @@ static ssize_t sys_param_store(struct kobject *kobj, ret = opal_set_sys_param(attr->param_id, attr->param_size, param_data_buf); mutex_unlock(&opal_sysparam_mutex); - return ret ? ret : count; + if (!ret) + ret = count; + return ret; } void __init opal_sys_param_init(void)