Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp4200575rwb; Tue, 20 Sep 2022 10:10:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5YuKipKyvCowreMZAevgTmQY0/wwQOniwlIZkO5xg4664Q9wiCOLfDzo1CnYTrDEqnSsP+ X-Received: by 2002:aa7:8759:0:b0:540:aad4:b13e with SMTP id g25-20020aa78759000000b00540aad4b13emr24673039pfo.13.1663693803749; Tue, 20 Sep 2022 10:10:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663693803; cv=none; d=google.com; s=arc-20160816; b=nUjh0wfiFaIXX9OY/3KH/z67fylzuMv1uTCCz+wafo/xI83vDtoTjd7ZQNBMywK15Y yibLhtGu6NKB8zSuzy4vSvPoKWVr+N0Xu8vFLEZI8xIpAFc1ENzUk/QmnuwpJTcrVs/s sMy0IFqI9j4zgiOBFewymPuCqekWvUfcfMbWceYyJ+hYCH4R83lKaCwHaZGGXOPe0dR0 +wD30yInj0tJGIcVfvzp8t798xHxEF/5yvdLdXZTePqeKF19Zc6ouPqZgk2DInKK93jU MRWp4x6qTDDOnlIJW3uYRkM/3SUHWvVbliK99J5WV1d00mOj5qOBkylX2f8xV6QecGLW fxvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version:date :subject:cc:to:from:dkim-signature:message-id; bh=ZV7szkCgBOcRGC1XpbuZJgXXL0O6qZY0z6Jlju1VTeg=; b=y/mGsZ1iOz8z6AnRcPtejyO6DgMhkog/l2+CyNZZBErKrj4pFmVeUpA+pPzXYpjtRC 7unQ7+1M8IYXvbHG5dGgQpHVJqsiQn8YX9vR7UqCmoTebielbKa+XRmeWfPQDGKkc5ET 4/Wf+FC3F3KzL9wZVVf5JWjTX8ulxIh0fAF+RSpzqfiCmpnUCjPEUTRqd9OdrL55N7II 2v5RX+I+G9dMlPDuCbZ3MwDyILC2hb95NLCmQ+0QqOlikwNltEJm7mV9C5mNWqp3BnZ3 2o+abHao8LNgCDvJVL6GHTsuPU+AmQc4SLygLbBTVq+oa5qe8LWhUTt1gDwyyiov+jVp 4lOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YqpKN9Gh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e7-20020a17090a9a8700b00200bbb9027asi263382pjp.77.2022.09.20.10.09.52; Tue, 20 Sep 2022 10:10:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YqpKN9Gh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Message-ID: <6329f3eb.170a0220.a46a1.6235SMTPIN_ADDED_BROKEN@mx.google.com> X-Google-Original-Message-ID: <20220920025158.70293-1-xhao@linux.alibaba.com> (raw) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230495AbiITQfs (ORCPT + 99 others); Tue, 20 Sep 2022 12:35:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230474AbiITQfp (ORCPT ); Tue, 20 Sep 2022 12:35:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67C296524F for ; Tue, 20 Sep 2022 09:35:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 03F6962531 for ; Tue, 20 Sep 2022 16:35:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7527C433D6; Tue, 20 Sep 2022 16:35:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663691743; bh=JiNzQhM8XzlrvxmA7lqX26ZtzWbfBJDZDlyLQ9Qps18=; h=From:To:Cc:Subject:Date:From; b=YqpKN9GhTuuH+yIaqEDa8uj1XIs7MEP138xHrkoiOoLyVcspLWFdDowIyvQUtWJdZ 6g2BtI6rF/snTRU9p4UWEG7NpLv4Z6XzpyQk9LTyN8BjmjIpmQmMyiPGjVaoiLOuqU zEzWgi6FI8HcK7KLA1HUbPwfX2u8w2ZhKHHiGtbtSmMSthOedHFEAhJnH3Kat5BbPT FP7Z54H4JUOcZMVrsIGNKruUVAAivBNJZgIr/lxhZ+45+lkqjA1oPImy7tf6yv/5V9 dSCZz3Sz7u5Mai4BlYgO1WHmidpK+ibmqgUIorEKPmpt3up2AxSG1R/hxPbY/I+0c+ oNvoBwR1Z4LGw== From: SeongJae Park To: sj@kernel.org Cc: Xin Hao , akpm@linux-foundation.org, damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] mm/damon/sysfs: return 'err' value when call kstrtoul() failed Date: Tue, 20 Sep 2022 16:35:30 +0000 X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xin Hao We had better return the 'err' value when calling kstrtoul() failed, so the user will know why it really fails, there do little change, let it return the 'err' value when failed. Suggested-by: SeongJae Park Signed-off-by: Xin Hao Reviewed-by: SeongJae Park Signed-off-by: SeongJae Park --- Changes from v2 (https://lore.kernel.org/damon/20220920025158.70293-1-xhao@linux.alibaba.com/) - Move patch changelog outside of the commit message area Changes from v1 (https://lore.kernel.org/linux-mm/20220919170305.61335-1-sj@kernel.org/T/) - keep the 'err' variable, and return the 'err' value when failed. mm/damon/sysfs.c | 46 ++++++++++++++-------------------------------- 1 file changed, 14 insertions(+), 32 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 0cca1909bf67..455215a5c059 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -58,7 +58,7 @@ static ssize_t min_store(struct kobject *kobj, struct kobj_attribute *attr, err = kstrtoul(buf, 0, &min); if (err) - return -EINVAL; + return err; range->min = min; return count; @@ -83,7 +83,7 @@ static ssize_t max_store(struct kobject *kobj, struct kobj_attribute *attr, err = kstrtoul(buf, 0, &max); if (err) - return -EINVAL; + return err; range->max = max; return count; @@ -291,9 +291,7 @@ static ssize_t interval_us_store(struct kobject *kobj, struct damon_sysfs_watermarks, kobj); int err = kstrtoul(buf, 0, &watermarks->interval_us); - if (err) - return -EINVAL; - return count; + return err ? err : count; } static ssize_t high_show(struct kobject *kobj, @@ -312,9 +310,7 @@ static ssize_t high_store(struct kobject *kobj, struct damon_sysfs_watermarks, kobj); int err = kstrtoul(buf, 0, &watermarks->high); - if (err) - return -EINVAL; - return count; + return err ? err : count; } static ssize_t mid_show(struct kobject *kobj, @@ -333,9 +329,7 @@ static ssize_t mid_store(struct kobject *kobj, struct damon_sysfs_watermarks, kobj); int err = kstrtoul(buf, 0, &watermarks->mid); - if (err) - return -EINVAL; - return count; + return err ? err : count; } static ssize_t low_show(struct kobject *kobj, @@ -354,9 +348,7 @@ static ssize_t low_store(struct kobject *kobj, struct damon_sysfs_watermarks, kobj); int err = kstrtoul(buf, 0, &watermarks->low); - if (err) - return -EINVAL; - return count; + return err ? err : count; } static void damon_sysfs_watermarks_release(struct kobject *kobj) @@ -437,9 +429,7 @@ static ssize_t sz_permil_store(struct kobject *kobj, struct damon_sysfs_weights, kobj); int err = kstrtouint(buf, 0, &weights->sz); - if (err) - return -EINVAL; - return count; + return err ? err : count; } static ssize_t nr_accesses_permil_show(struct kobject *kobj, @@ -458,9 +448,7 @@ static ssize_t nr_accesses_permil_store(struct kobject *kobj, struct damon_sysfs_weights, kobj); int err = kstrtouint(buf, 0, &weights->nr_accesses); - if (err) - return -EINVAL; - return count; + return err ? err : count; } static ssize_t age_permil_show(struct kobject *kobj, @@ -479,9 +467,7 @@ static ssize_t age_permil_store(struct kobject *kobj, struct damon_sysfs_weights, kobj); int err = kstrtouint(buf, 0, &weights->age); - if (err) - return -EINVAL; - return count; + return err ? err : count; } static void damon_sysfs_weights_release(struct kobject *kobj) @@ -1111,9 +1097,7 @@ static ssize_t start_store(struct kobject *kobj, struct kobj_attribute *attr, struct damon_sysfs_region, kobj); int err = kstrtoul(buf, 0, ®ion->start); - if (err) - return -EINVAL; - return count; + return err ? err : count; } static ssize_t end_show(struct kobject *kobj, struct kobj_attribute *attr, @@ -1132,9 +1116,7 @@ static ssize_t end_store(struct kobject *kobj, struct kobj_attribute *attr, struct damon_sysfs_region, kobj); int err = kstrtoul(buf, 0, ®ion->end); - if (err) - return -EINVAL; - return count; + return err ? err : count; } static void damon_sysfs_region_release(struct kobject *kobj) @@ -1528,7 +1510,7 @@ static ssize_t sample_us_store(struct kobject *kobj, int err = kstrtoul(buf, 0, &us); if (err) - return -EINVAL; + return err; intervals->sample_us = us; return count; @@ -1552,7 +1534,7 @@ static ssize_t aggr_us_store(struct kobject *kobj, struct kobj_attribute *attr, int err = kstrtoul(buf, 0, &us); if (err) - return -EINVAL; + return err; intervals->aggr_us = us; return count; @@ -1576,7 +1558,7 @@ static ssize_t update_us_store(struct kobject *kobj, int err = kstrtoul(buf, 0, &us); if (err) - return -EINVAL; + return err; intervals->update_us = us; return count; -- 2.31.0