From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755726AbcIAP3t (ORCPT ); Thu, 1 Sep 2016 11:29:49 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:43476 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753986AbcIAP3q (ORCPT ); Thu, 1 Sep 2016 11:29:46 -0400 X-IBM-Helo: d01dlp02.pok.ibm.com X-IBM-MailFrom: arbab@linux.vnet.ibm.com From: Reza Arbab To: Greg Kroah-Hartman , Andrew Morton , Vlastimil Babka , Vitaly Kuznetsov , David Rientjes , Yaowei Bai , Joonsoo Kim , Dan Williams , Xishi Qiu , David Vrabel , Chen Yucong , Andrew Banman , Seth Jennings , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] memory-hotplug: fix store_mem_state() return value Date: Thu, 1 Sep 2016 10:29:37 -0500 X-Mailer: git-send-email 1.8.3.1 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16090115-0056-0000-0000-00000138E65B X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00005692; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000184; SDB=6.00752511; UDB=6.00355806; IPR=6.00525381; BA=6.00004686; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00012548; XFM=3.00000011; UTC=2016-09-01 15:29:44 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16090115-0057-0000-0000-00000552F97B Message-Id: <1472743777-24266-1-git-send-email-arbab@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-09-01_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1609010169 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If store_mem_state() is called to online memory which is already online, it will return 1, the value it got from device_online(). This is wrong because store_mem_state() is a device_attribute .store function. Thus a non-negative return value represents input bytes read. Set the return value to -EINVAL in this case. Signed-off-by: Reza Arbab --- v2 -> v3: * David Rientjes pointed out that the backwards-compatible return value in this situation is -EINVAL, not success. I had mistakenly thought the behavior should be the same as online_store(). drivers/base/memory.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 1cea0ba..bb69e58 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -359,8 +359,11 @@ store_mem_state(struct device *dev, err: unlock_device_hotplug(); - if (ret) + if (ret < 0) return ret; + if (ret) + return -EINVAL; + return count; } -- 1.8.3.1