From owner-dev-commits-src-main@freebsd.org Tue May 18 14:16:06 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C42E964DF34; Tue, 18 May 2021 14:16:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Fkyj25Bszz4XDh; Tue, 18 May 2021 14:16:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 99C8D20B43; Tue, 18 May 2021 14:16:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 14IEG68b010246; Tue, 18 May 2021 14:16:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 14IEG6cT010245; Tue, 18 May 2021 14:16:06 GMT (envelope-from git) Date: Tue, 18 May 2021 14:16:06 GMT Message-Id: <202105181416.14IEG6cT010245@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Hans Petter Selasky Subject: git: 00e501d720d4 - main - Update usb_timings_sysctl_handler() to accept any value for timings between 0 milliseconds and 2 seconds inclusivly. Some style fixes while at it. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: hselasky X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 00e501d720d46386e6c8d0ebb4b3a8e98cb0390e Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 May 2021 14:16:06 -0000 The branch main has been updated by hselasky: URL: https://cgit.FreeBSD.org/src/commit/?id=00e501d720d46386e6c8d0ebb4b3a8e98cb0390e commit 00e501d720d46386e6c8d0ebb4b3a8e98cb0390e Author: Hans Petter Selasky AuthorDate: 2021-05-18 13:16:29 +0000 Commit: Hans Petter Selasky CommitDate: 2021-05-18 13:52:41 +0000 Update usb_timings_sysctl_handler() to accept any value for timings between 0 milliseconds and 2 seconds inclusivly. Some style fixes while at it. The USB specification has minimum values and maximum values, and not only minimum values. MFC after: 1 week Sponsored by: Mellanox Technologies // NVIDIA Networking --- sys/dev/usb/usb_debug.c | 57 +++++++++++-------------------------------------- 1 file changed, 13 insertions(+), 44 deletions(-) diff --git a/sys/dev/usb/usb_debug.c b/sys/dev/usb/usb_debug.c index 5b5d141508c3..5e521f7ec3a5 100644 --- a/sys/dev/usb/usb_debug.c +++ b/sys/dev/usb/usb_debug.c @@ -249,71 +249,40 @@ unsigned int usb_extra_power_up_time = USB_EXTRA_POWER_UP_TIME; /*------------------------------------------------------------------------* * usb_timings_sysctl_handler * - * This function updates timings variables, adjusting them where necessary. + * This function is used to update USB timing variables. *------------------------------------------------------------------------*/ static int usb_timings_sysctl_handler(SYSCTL_HANDLER_ARGS) { int error = 0; - unsigned int val; + unsigned val; /* * Attempt to get a coherent snapshot by making a copy of the data. */ if (arg1) - val = *(unsigned int *)arg1; + val = *(unsigned *)arg1; else val = arg2; - error = SYSCTL_OUT(req, &val, sizeof(int)); + error = SYSCTL_OUT(req, &val, sizeof(unsigned)); if (error || !req->newptr) return (error); if (!arg1) - return EPERM; + return (EPERM); - error = SYSCTL_IN(req, &val, sizeof(unsigned int)); + error = SYSCTL_IN(req, &val, sizeof(unsigned)); if (error) return (error); /* - * Now make sure the values are decent, and certainly no lower than - * what the USB spec prescribes. + * Make sure the specified value is not too big. Accept any + * value from 0 milliseconds to 2 seconds inclusivly for all + * parameters. */ - unsigned int *p = (unsigned int *)arg1; - if (p == &usb_port_reset_delay) { - if (val < USB_PORT_RESET_DELAY_SPEC) - return (EINVAL); - } else if (p == &usb_port_root_reset_delay) { - if (val < USB_PORT_ROOT_RESET_DELAY_SPEC) - return (EINVAL); - } else if (p == &usb_port_reset_recovery) { - if (val < USB_PORT_RESET_RECOVERY_SPEC) - return (EINVAL); - } else if (p == &usb_port_powerup_delay) { - if (val < USB_PORT_POWERUP_DELAY_SPEC) - return (EINVAL); - } else if (p == &usb_port_resume_delay) { - if (val < USB_PORT_RESUME_DELAY_SPEC) - return (EINVAL); - } else if (p == &usb_set_address_settle) { - if (val < USB_SET_ADDRESS_SETTLE_SPEC) - return (EINVAL); - } else if (p == &usb_resume_delay) { - if (val < USB_RESUME_DELAY_SPEC) - return (EINVAL); - } else if (p == &usb_resume_wait) { - if (val < USB_RESUME_WAIT_SPEC) - return (EINVAL); - } else if (p == &usb_resume_recovery) { - if (val < USB_RESUME_RECOVERY_SPEC) - return (EINVAL); - } else if (p == &usb_extra_power_up_time) { - if (val < USB_EXTRA_POWER_UP_TIME_SPEC) - return (EINVAL); - } else { - /* noop */ - } + if (val > 2000) + return (EINVAL); - *p = val; - return 0; + *(unsigned *)arg1 = val; + return (0); } #endif