From nobody Thu Nov 23 17:41:36 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Sblm25gKZz528Mk; Thu, 23 Nov 2023 17:41:38 +0000 (UTC) (envelope-from mhorne@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (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 "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Sblm25BClz3HMx; Thu, 23 Nov 2023 17:41:38 +0000 (UTC) (envelope-from mhorne@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700761298; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=tBYVRC4pxHJ+/uqIvQ/RignNcsX+IM5ieMZBsv3b1ig=; b=ZxgXfvBuF/vNZddE1aRPwExV52jDu4KLCAES77bsru4CLQIQTWrN3bYndJPVtZ4hG7BVJ6 zpmlXiZi1Limh0NZ3PyxtLtAQszXq2vQDvDPu962CA6HmrkIA4nYvoJZzDBcDdhO0SfD8Y clBFh7UAJTYOAke936vqi4BT4TrEeO2VxaCyenZ3XI+z4SzfXcK2pemvIuV+qCgm2GRZBB m00070o4eJjRgDVl80m5aonvEg9XNW/M4ksTAYA4NmhzcntiHsjcTjybHDCUibQODwKr5L 5yNR9Yp37kxVwtrdrnK2mR9fPrLUOduI7ZLXaeyYYM5O5Ijn6nFyhc1BUVpQIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700761298; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=tBYVRC4pxHJ+/uqIvQ/RignNcsX+IM5ieMZBsv3b1ig=; b=GHxomRgWq4vpeaUXEe804eZsxfNIRTZlU1xJo8wrjfimkQMaekOmmXvxPSey3nx5Pf2Kg9 be8JTXtK/EdeIwqTvTscBVn3Rx/xjUSoLGt9q1Bi4tHZQRTmweLSepXbTGEBltiqUaAf3D P/sxANifyGhNHSg2inPKroluPaNc1K6wRyyHivs/osuVTw0ZEDOztjcXBhndHLmqP5SqCz xt0AQ2qwnATrYgbqJq+xcE5aeKxw3KpcsYv48yYzo5i5A5OavCM0pCAsxhBzovlAMxkxT/ MNV8eGqG5NO/+I0kZjHCBhGoHqcgQkNw37NWBUrl4ExzWh5suK46bGt+NbPNDg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1700761298; a=rsa-sha256; cv=none; b=KfIZMxisWz3PXewnvXq1jTAtidOBam7S4NhQ4Kiz8npbsGcUtxIg3iHdKtK3dIi2vciTU+ +VgNjW6IolJdWajLSmpm7dHeyvGuqLBCLWCSukZMeK0WM1yqtqo7rGsb6y6wMP/x7GsRcp ru8e01Z0G8oUnsPMEk1Q7vjbeXDHHBvjnMCZtyPe+Gfaqsu8ah4fXinRYpzyOZvS9ggiKj FTJFZGpmVNHg+N0IM1gTmLmCKAaLf/8by7qP2dqDTb6KN4tjqpxYl8fZ+Ojp7921xrbLkM 569rB6k2ATUAfmM3qYFhJd2X+z1I0C2CyDqJh1cKmeXh6jnOvKAl0ivP74jq1Q== Received: from [192.168.1.151] (host-173-212-76-127.public.eastlink.ca [173.212.76.127]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: mhorne) by smtp.freebsd.org (Postfix) with ESMTPSA id 4Sblm22Fm5z14kV; Thu, 23 Nov 2023 17:41:38 +0000 (UTC) (envelope-from mhorne@freebsd.org) Message-ID: <48b90d6b-5772-4aba-8948-bcf8b50c9b5b@freebsd.org> Date: Thu, 23 Nov 2023 13:41:36 -0400 List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: git: 19f073c612af - main - new-bus: Add resource_validate_map_request function Content-Language: en-CA To: John Baldwin , src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org References: <202311231707.3ANH758D008755@gitrepo.freebsd.org> From: Mitchell Horne Autocrypt: addr=mhorne@freebsd.org; keydata= xsBNBFyS2dQBCADdiXBG8hBVLmYbxu7aSzbwLwUf3HkGFz3rooS1kwyy+SfmjZ4UKNnl9WMx WKrJ7OAZpiNH6bLQ5nsqfx09OnpWL8c/QuPbhNdUywQoqqYpRI0K8GEn//nS9Gs0KTYwVpWb XlrzP+jf3Uh/9L5mcQmStLIH4zaaqMYHW+pMuPrvBmLIHTvLj2QjOkxslrcUdord9uvxe5Ht LU8RuTpQpHOKz705Z9/v7twFdi2HtKzpLwO6SzVyu351di1J+GihsVpcT5josQV5cHbIP3Un x+kmtKBEEc/jl/zBglF7ruWUtwgbryID+2ZPEaO1Mj+RResX4LFVMusq3uUpWRb5WJXxABEB AAHNI01pdGNoZWxsIEhvcm5lIDxtaG9ybmVARnJlZUJTRC5vcmc+wsCUBBMBCgA+AhsDBQsJ CAcCBhUKCQgLAgQWAgMBAh4BAheAFiEEkp/cYPcfabAiQvACi/gnTOdUid8FAmIyDpUFCQtC z0E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glwd bjsZNfXIJGOZNEvdF8FOBwM7DlXx7SYvTJcUNoNJjOKtQ0bYGVgGqYOB/y2mTjVuKeU0eOkN Uw== In-Reply-To: <202311231707.3ANH758D008755@gitrepo.freebsd.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 11/23/23 13:07, John Baldwin wrote: > The branch main has been updated by jhb: > > URL: https://cgit.FreeBSD.org/src/commit/?id=19f073c612afa0111d216e5ccab9525bfc97ec32 > > commit 19f073c612afa0111d216e5ccab9525bfc97ec32 > Author: John Baldwin > AuthorDate: 2023-11-23 17:06:24 +0000 > Commit: John Baldwin > CommitDate: 2023-11-23 17:06:24 +0000 > > new-bus: Add resource_validate_map_request function > > This helper function for BUS_MAP_RESOURCE performs common argument > validation. > > Reviewed by: imp > Differential Revision: https://reviews.freebsd.org/D42723 > --- > sys/kern/subr_bus.c | 31 +++++++++++++++++++++++++++++++ > sys/sys/bus.h | 6 +++++- > 2 files changed, 36 insertions(+), 1 deletion(-) > > diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c > index 648394abd026..80fe182eab56 100644 > --- a/sys/kern/subr_bus.c > +++ b/sys/kern/subr_bus.c > @@ -2715,6 +2715,37 @@ resource_init_map_request_impl(struct resource_map_request *args, size_t sz) > args->memattr = VM_MEMATTR_DEVICE; > } > > +int > +resource_validate_map_request(struct resource *r, > + struct resource_map_request *in, struct resource_map_request *out, > + rman_res_t *startp, rman_res_t *lengthp) Can the function be given a top-level comment stating its purpose? This file does a really good job providing this for the majority of its public functions. Sorry to ask post-commit, but I did not see the review. Mitchell > +{ > + rman_res_t end, length, start; > + > + /* > + * This assumes that any callers of this function are compiled > + * into the kernel and use the same version of the structure > + * as this file. > + */ > + MPASS(out->size == sizeof(struct resource_map_request)); > + > + if (in != NULL) > + bcopy(in, out, imin(in->size, out->size)); > + start = rman_get_start(r) + out->offset; > + if (out->length == 0) > + length = rman_get_size(r); > + else > + length = out->length; > + end = start + length - 1; > + if (start > rman_get_end(r) || start < rman_get_start(r)) > + return (EINVAL); > + if (end > rman_get_end(r) || end < start) > + return (EINVAL); > + *lengthp = length; > + *startp = start; > + return (0); > +} > + > /** > * @brief Initialise a resource list. > * > diff --git a/sys/sys/bus.h b/sys/sys/bus.h > index fc07cf70f78a..88ae4000004b 100644 > --- a/sys/sys/bus.h > +++ b/sys/sys/bus.h > @@ -317,6 +317,8 @@ struct driver { > KOBJ_CLASS_FIELDS; > }; > > +struct resource; > + > /** > * @brief A resource mapping. > */ > @@ -341,12 +343,14 @@ void resource_init_map_request_impl(struct resource_map_request *_args, > size_t _sz); > #define resource_init_map_request(rmr) \ > resource_init_map_request_impl((rmr), sizeof(*(rmr))) > +int resource_validate_map_request(struct resource *r, > + struct resource_map_request *in, struct resource_map_request *out, > + rman_res_t *startp, rman_res_t *lengthp); > > /* > * Definitions for drivers which need to keep simple lists of resources > * for their child devices. > */ > -struct resource; > > /** > * @brief An entry for a single resource in a resource list.