From patchwork Fri Feb 2 03:00:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guan-Yu Lin X-Patchwork-Id: 195548 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp176071dyc; Thu, 1 Feb 2024 19:04:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IGCUB6o3OiJ7litv1ttGtxPyESwil7YVW4VXZov3Xiqrd5n7hTh2y+TKzjdb2jb2lR7wQf0 X-Received: by 2002:a25:ac4:0:b0:dc6:be1f:6d98 with SMTP id 187-20020a250ac4000000b00dc6be1f6d98mr6188177ybk.16.1706843080365; Thu, 01 Feb 2024 19:04:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706843080; cv=pass; d=google.com; s=arc-20160816; b=aSHwDGFYgDkMDu+UM/ZDaN4hJVyJ3GSMe/u07riqsDZxDMvQdS+hbFByCTFdNWrDfV tHWra2/0JXNYFKmQzx5F4JBmsvLeIyHFRl/2YgBP1OnIuDhDmfgAuT2Hy8zVM1vfkggm 5p6H97VNoga9QMv4PRfn8ARELpW0AhVAz69OIjvV/t1CZeol73fuWmX4f2SJymabXSF2 2UA1pdzo1zUwlAOe4XJbTt2XHV3hHi4wNf73MtXzU/GQeCBARBmQ/UAo32TqFedJThPN h2k0pboeJzgjgkvSj6L8Xpj6aRel7ctsF5RHvMd1sN//iidFzAFW1K6YNnZewJBtYHds u55A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=NBFBnWt5PngE+9c3SBPlpOUFG8K2Vi64DLTgnygvKiw=; fh=frK/JVc15PKd2hDCH14WcXiFO5W57ztAhKdOaDJnqYU=; b=z/ncnx/Jt5/VlDFP7PUP1pVBMFQZjJrNRjMSKELHJ3YV6KpC+gTMZ+H+BqxaNiyvSb wHOtg0tHnkALCtY1bu+Keq3Lt4Zk+8C9aiVFaNnRMeQksgDWQVhQdGiUQ4raMWR5UOV1 deht56rn1UZW2cn8phSkNVosDuN9w+wZlj5vPJHxbN1QDcaMbRmlnXQiGPYwZFPo9MRF 7ujRvzrCr9jmCyq8ZkWW3fGb67YQjPmK2W7LX13hLFeFnrW59yzTmzr2zRjQXV1pbcGs O4L3RCtcibF8ZEMjPz3aizypZxu8g+ayafrtFU/scL1u+NIR94nU0ZeSPELG7Nkj9cfj 5fmA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=A1qsG+aa; arc=pass (i=1 spf=pass spfdomain=flex--guanyulin.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-49130-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49130-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCU+gkFNEF4WDqX0smp8mji1/gxe3elRuUns4qO76I5tEk9cICecoZAxWAA9CxVjcO+R25icoCgz1nu32B/EWL3eX5oFUg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c9-20020a0cfb09000000b0068c3a96d43dsi994710qvp.218.2024.02.01.19.04.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 19:04:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49130-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=A1qsG+aa; arc=pass (i=1 spf=pass spfdomain=flex--guanyulin.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-49130-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49130-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 1B9EE1C242E6 for ; Fri, 2 Feb 2024 03:04:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C86C5BE5C; Fri, 2 Feb 2024 03:04:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="A1qsG+aa" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1BFC2C2D2 for ; Fri, 2 Feb 2024 03:04:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706843060; cv=none; b=IRx7V6h3TS7FMAHPTvKtcVPvbSrl2iuouMsHnOLEBPU9DgVJZ4scf+sg3BOGS5HO4Ydw12Ir7giDA14S6Q8MV1OYZ4ldOtW0sCCk+dq9qjPtKg2z0OMqesLrvgUqzzOTIvrLs7lxULtHfc9Tyq21/dak3CZ1hUns3a0Pj53ZoJ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706843060; c=relaxed/simple; bh=7fvoMDGLvlhYIzv6i+KgK8j9y8CMOHfEAGQsrvtQc14=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=KyL54jnp7GMzfoh/JtrAwrcTm543x9uRLyxVHnH7z2C7PqmQgvcZ/6fxjHaJE1lGHnNh/EWIcS7ePgC97tI+atiRXenU4thUd+2eSftJbrt0ZKMpvZgEZb+SW3TFwtOJHvvOJnKy9UqvLlIAgXagqvmRPMWJkmKMadKInV1OzzA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--guanyulin.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=A1qsG+aa; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--guanyulin.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc647f65573so2794196276.2 for ; Thu, 01 Feb 2024 19:04:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706843058; x=1707447858; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=NBFBnWt5PngE+9c3SBPlpOUFG8K2Vi64DLTgnygvKiw=; b=A1qsG+aagv8qJyA4r/IQdvg6N1KYFB2gEYWWTWbx4qc3OSsy5gZGqZea028rpsVy2I uVkpldcNp1VD1VGSJBPXhugZlnlVRGOkUqXKuMGqmWx58mHgm2Da/oP0KQojRShVo1l2 Dj1+iEUH2a6DUCsrqjtZJkObaBHYsX0pe9GgPuajsqYWAAG5Tnaq1tx2VKkwle/8UXdH DDCiW/+hrmAfdStbYkFA1LbXvCOXNqlpXkyTVFSx04jyMxpdb7o33DbFLOJhFr06UvBX Id9EAixwwTY8syaH0VZlKiNbp4aLnGIsZgxFBKupvs2WJ2UxxzcEvWoMP8a0I5Xdb7Wi sgMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706843058; x=1707447858; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=NBFBnWt5PngE+9c3SBPlpOUFG8K2Vi64DLTgnygvKiw=; b=ZO/UPM8JrrRMJ0v+QMQBWm7EWR2X64qK6+S2IXFr0gP9xhZ3raZwXLqP3u6WeerC/m hKnSpLis6+2BBwbgdbk2Afz7KQyMdaAP/Bofbo0yHEhjaEu0E0MI2FIjDx/FcM+cmCOr azDB3tr+QGHWTy+bIN8qkHsNYvUiIqjFsgwodOFKYy3gY30+XTEbD/3lE/ooJAQAwGNk FWdznYXEOjaBeTquy9n76LhnyHJJRP5YqNJtWnj8Xhhw6Jb0oOrpCy0LLnWhTq20KsRF atp7UOVf1PjzRRtqFemrqPoZ2NepZr7WGq2qUHhknJjx3ELEuoPtzf7f/JE+kPNTyIXJ /Njw== X-Gm-Message-State: AOJu0Yzex/iLFDkqX38/Zlj/r5K9ErTZxhioOR7gELsVLwymaUxqsecI Yuy7oOAPP1Nt5JCUanJsG8wC+fT8E/xQjTaLJit+2cS+gGX3g8jzkz1bZkzDqyDd3C4TCVXF81Z Sdr58aQhUVS909Q== X-Received: from guanyulin.c.googlers.com ([fda3:e722:ac3:cc00:3:22c1:c0a8:1af]) (user=guanyulin job=sendgmr) by 2002:a05:6902:2491:b0:dc6:e8a7:fdba with SMTP id ds17-20020a056902249100b00dc6e8a7fdbamr391501ybb.4.1706843058023; Thu, 01 Feb 2024 19:04:18 -0800 (PST) Date: Fri, 2 Feb 2024 03:00:42 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Message-ID: <20240202030301.2396374-1-guanyulin@google.com> Subject: [PATCH] usb: sysfs: use kstrtobool() if possible From: Guan-Yu Lin To: gregkh@linuxfoundation.org, stern@rowland.harvard.edu, benjamin.tissoires@redhat.com, hadess@hadess.net Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Guan-Yu Lin X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789754689953892239 X-GMAIL-MSGID: 1789754689953892239 Replace the self-rolled implementations with kstrtobool(). This reduces the maintenance efforts in the future. Signed-off-by: Guan-Yu Lin --- drivers/usb/core/sysfs.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c index 5d21718afb05..e67826ec053e 100644 --- a/drivers/usb/core/sysfs.c +++ b/drivers/usb/core/sysfs.c @@ -273,9 +273,10 @@ static ssize_t avoid_reset_quirk_store(struct device *dev, const char *buf, size_t count) { struct usb_device *udev = to_usb_device(dev); - int val, rc; + bool val; + int rc; - if (sscanf(buf, "%d", &val) != 1 || val < 0 || val > 1) + if (kstrtobool(buf, &val) != 0) return -EINVAL; rc = usb_lock_device_interruptible(udev); if (rc < 0) @@ -322,13 +323,14 @@ static ssize_t persist_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct usb_device *udev = to_usb_device(dev); - int value, rc; + bool value; + int rc; /* Hubs are always enabled for USB_PERSIST */ if (udev->descriptor.bDeviceClass == USB_CLASS_HUB) return -EPERM; - if (sscanf(buf, "%d", &value) != 1) + if (kstrtobool(buf, &value) != 0) return -EINVAL; rc = usb_lock_device_interruptible(udev); @@ -739,14 +741,14 @@ static ssize_t authorized_store(struct device *dev, { ssize_t result; struct usb_device *usb_dev = to_usb_device(dev); - unsigned val; - result = sscanf(buf, "%u\n", &val); - if (result != 1) + bool val; + + if (kstrtobool(buf, &val) != 0) result = -EINVAL; - else if (val == 0) - result = usb_deauthorize_device(usb_dev); - else + else if (val) result = usb_authorize_device(usb_dev); + else + result = usb_deauthorize_device(usb_dev); return result < 0 ? result : size; } static DEVICE_ATTR_IGNORE_LOCKDEP(authorized, S_IRUGO | S_IWUSR,