Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp10649723rwp; Fri, 21 Jul 2023 02:43:09 -0700 (PDT) X-Google-Smtp-Source: APBJJlHYMVlyX//ha/rdk7DZOr5yao08wZF74MvcwgnilHKqddWs1qCTM+2m2BIGIfe6WqNTPdvU X-Received: by 2002:aa7:d888:0:b0:51b:df62:4f0b with SMTP id u8-20020aa7d888000000b0051bdf624f0bmr995677edq.6.1689932588789; Fri, 21 Jul 2023 02:43:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689932588; cv=none; d=google.com; s=arc-20160816; b=cUzzieZxGw6xN3+Gx0MF1Tkp9bfZicK2Sk4tPvypO3S42Oq86iJOTS8OS/GrclYyMW v67HDouleAaTX6dfl7rVyLm/vg2VbhUnLfOCesg2/re4mIPq4b+cmCiWVdo4IMPuX0T/ OpVeBwdizWVt4QHYJEzh3DZp4XwIxNVJgYMUz9D7hGX3gwGHgbDQqijOL2w32hcGk+wt bsFgduChTlh38CXyxJ34eilWRybMqUaPfrQ+YfXvvI4VlhTESgxWgtqUYZrzwA23sIF1 Pu2I4T5X5937L6ll7j7QSj4Vq9U8+3GOKT52vyzz9zQfHx3f2uSsrBDal+YA0uIq5m5U jiwA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=tCflDaV8zc69JhQDjjJilHCHdTvzcdDmX3C6lC+uvr4=; fh=7RuZVHvwAj74FNHTgOXk6lvFEXP3wdynNPCTlYZdPBk=; b=ZlntnGZN87cDAK2oxkk+PUGkvRs4++E7cZ47pdlftyhnJKzX1wbkU6RPAXkm/mn/qc 2StQxOiVqyxItt0LsfRN2ddSOte3bUh/caxbUMkWJqncAuoo/gLSpuRGl4WYKC3vG66C 0BPmMaXJDsNgyFjFBhy5qqdaC9UDZTjvy4o5EAWVOtkH90jaPAAqzyFU/6Zza0wOvC6b rtrGsuNhY6xqqI9PCOT+e2jkqNIHmL5mBjUjz27arS8o2zjX/hP7Mv7KEdtlI3GUSheu MAZnZ3t6z5MIlaD0GGCCrum2ir8mz7I179po+W1a9S2enOCQ4g8ns8HQBtAHc7iw1jEA naLA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o19-20020aa7c513000000b0051e0eba60bdsi2177417edq.456.2023.07.21.02.42.44; Fri, 21 Jul 2023 02:43:08 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231778AbjGUJWR (ORCPT + 99 others); Fri, 21 Jul 2023 05:22:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231775AbjGUJWK (ORCPT ); Fri, 21 Jul 2023 05:22:10 -0400 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E75FA30E1; Fri, 21 Jul 2023 02:22:02 -0700 (PDT) Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-993a37b79e2so271183866b.1; Fri, 21 Jul 2023 02:22:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689931321; x=1690536121; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tCflDaV8zc69JhQDjjJilHCHdTvzcdDmX3C6lC+uvr4=; b=i3LGgn9aX67POknKwfpDma8GVzNrXq+e+pVS+oRcNH6WsOVbnleROIpZZ660qID78f JgjxuJBmgsB38+KIv+wba/WGoh0c6EvMZCLpMOI+giNt+EMb4EVOJ6i8F99IvJsBquTi PVADBkhxMetS5p9vUaaMMk7t6PYgt/CyU8iurPzxYIqNYfbMmwzwRh2sKuzjS7Umz0rb bnFrJ56ylmV27PIsetSWnI0gMt1sTpgUrUt3586hkHmQ3eD0fDlqwi9ZZORVQFHOPk8x RzKnqaqVBP0zd74FW0xUxujzd92mqfVXqtG+tnYTyl1b+4266YJ3kGAaW4/6xDUCRWUF 85Bw== X-Gm-Message-State: ABy/qLbHyQb91JHLoBGnjMj4h0lkSyJ5SuxFz/rhwwcQA8ljeOtmgK+6 U9oafGhGFk2zCiReJ09YrheTo7FA8nQ= X-Received: by 2002:a17:907:7817:b0:99b:4210:cc75 with SMTP id la23-20020a170907781700b0099b4210cc75mr1171431ejc.40.1689931320897; Fri, 21 Jul 2023 02:22:00 -0700 (PDT) Received: from localhost (fwdproxy-cln-016.fbsv.net. [2a03:2880:31ff:10::face:b00c]) by smtp.gmail.com with ESMTPSA id dk20-20020a170906f0d400b00992ab0262c9sm1927268ejb.147.2023.07.21.02.22.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jul 2023 02:22:00 -0700 (PDT) From: Breno Leitao To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: leit@meta.com, Petr Mladek , netdev@vger.kernel.org (open list:NETWORKING DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next 2/2] netconsole: Use kstrtobool() instead of kstrtoint() Date: Fri, 21 Jul 2023 02:21:45 -0700 Message-Id: <20230721092146.4036622-2-leitao@debian.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230721092146.4036622-1-leitao@debian.org> References: <20230721092146.4036622-1-leitao@debian.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no 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 Replace kstrtoint() by kstrtobool() in the sysfs _store() functions. This improves the user usability and simplify the code. With this fix, it is now possible to use [YyNn] to set and unset a feature. Old behaviour is still unchanged. kstrtobool() is also safer and doesn't need the extra validation that is required when converting a string to bool (end field in the struct), which makes the code simpler. Suggested-by: Petr Mladek Signed-off-by: Breno Leitao --- drivers/net/netconsole.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index a3c53b8c9efc..87f18aedd3bd 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -333,17 +333,15 @@ static ssize_t enabled_store(struct config_item *item, { struct netconsole_target *nt = to_target(item); unsigned long flags; - int enabled; + bool enabled; int err; mutex_lock(&dynamic_netconsole_mutex); - err = kstrtoint(buf, 10, &enabled); - if (err < 0) + err = kstrtobool(buf, &enabled); + if (err) goto out_unlock; err = -EINVAL; - if (enabled < 0 || enabled > 1) - goto out_unlock; if ((bool)enabled == nt->enabled) { pr_info("network logging has already %s\n", nt->enabled ? "started" : "stopped"); @@ -394,7 +392,7 @@ static ssize_t release_store(struct config_item *item, const char *buf, size_t count) { struct netconsole_target *nt = to_target(item); - int release; + bool release; int err; mutex_lock(&dynamic_netconsole_mutex); @@ -405,13 +403,9 @@ static ssize_t release_store(struct config_item *item, const char *buf, goto out_unlock; } - err = kstrtoint(buf, 10, &release); - if (err < 0) - goto out_unlock; - if (release < 0 || release > 1) { - err = -EINVAL; + err = kstrtobool(buf, &release); + if (err) goto out_unlock; - } nt->release = release; @@ -426,7 +420,7 @@ static ssize_t extended_store(struct config_item *item, const char *buf, size_t count) { struct netconsole_target *nt = to_target(item); - int extended; + bool extended; int err; mutex_lock(&dynamic_netconsole_mutex); @@ -437,13 +431,9 @@ static ssize_t extended_store(struct config_item *item, const char *buf, goto out_unlock; } - err = kstrtoint(buf, 10, &extended); - if (err < 0) - goto out_unlock; - if (extended < 0 || extended > 1) { - err = -EINVAL; + err = kstrtobool(buf, &extended); + if (err) goto out_unlock; - } nt->extended = extended; -- 2.34.1