From nobody Thu Nov 23 17:07:06 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 4Sbl0B71k3z5227l; Thu, 23 Nov 2023 17:07: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 4Sbl0B6Qrdz3CPs; Thu, 23 Nov 2023 17:07:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700759226; 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; bh=upsC1QuaHv92hlSqDi1YsbcgX1ZX6PCldjC9YHl1mQk=; b=Ce0lsZvs086+l28U4Xg3kJFh0fR/FIdNmwP/kUrOfLY0o6ThfES9xhmUT7GrW6cbwKZLAo qqSo3AluVknmC0RqflI1XrBltnkNJENGBobokB5ILq/cLa2zZ0Sd05OI2L6CYSdg9fXaUC bRwqFgvUIvz/Y+4DJbX5AyUrgCOn5yHHu8t+mwJctMqaszk0nKhVaISHMKi8ne1SbJb2kY w1NKkcoH6EUQ5K5PinIbJLcbaXp6gwO8kbab3aCrqx66FlSTxcerPM/uc9xD3hT9j0cRYW 0VRHHl7jcsYxqEArRdVwV8xd+wS8PxFfvtakGPQc3IzVxm21Z3FrSA32zDDvRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700759226; 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; bh=upsC1QuaHv92hlSqDi1YsbcgX1ZX6PCldjC9YHl1mQk=; b=NUp/pOU/aj4vNhYaMukC6l/KXgAEHjgJv0BLJ2lsSQ2rbWNyJnbe40GSZRCq9OuQ3jC5aK XjO0i7bdoUHKftQrYrJ6ZLco1AWfN9BzwtthUs0eHu8HIrOy8I9AHHGkMY7cAQKtgo8nHs AlreNLJ8ha6gQzykvthQhOWQPNaYa61+LZHODKIsRVMWxjVApYKYv29AepoMctTXpuQLGJ 7HiNZffPizE7lGsaeqfKv/yZrXUyOdEA41x5Pn7kGfl8Lg3UktXAV6VL/Y2LLtjgTuYkOM Ew7BMxGsZQ8F43MlUxzSRSio0MUsvX/B/HvR3Iqz7+JliIAHSRFl9xxSPbFGsg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1700759226; a=rsa-sha256; cv=none; b=qfl6XhT4JdVh97FCqAEG+urG3Fh9uw18j7cwyfs4v0/0EVTbT/72BvXq6ySuAWa81MBAXQ TGu99ZQZT4sEchIWmA4b2tcaayOjL3H1h8d9CRElY9uPJyEpgBQ2l/+DoKHlmjlVcklGnW OHN0l5Y0A4bPpwh2cCNt+8ysmlw+/UWFPtqTAUSORr7tPm99wOpFOH2vX3dglCmQg4jujq SgRkLxUTcrjASc+ZUhi6kZ2TPI021N610GbTMMDV+myXqIKAZneAhxSLBXmNzrXrt9Uu+o CEi2fGG1TOkCKObgSf7WOVm3FQ1slHQtUdUkMmBkuvRpJhh26r1PUQByzaOlUA== 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 4Sbl0B4rqKz199b; Thu, 23 Nov 2023 17:07:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3ANH7632008794; Thu, 23 Nov 2023 17:07:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3ANH76ki008791; Thu, 23 Nov 2023 17:07:06 GMT (envelope-from git) Date: Thu, 23 Nov 2023 17:07:06 GMT Message-Id: <202311231707.3ANH76ki008791@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: b887b665ebc0 - main - nexus: Use resource_validate_map_request 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 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b887b665ebc044f246d261e8af543765b846ed38 Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=b887b665ebc044f246d261e8af543765b846ed38 commit b887b665ebc044f246d261e8af543765b846ed38 Author: John Baldwin AuthorDate: 2023-11-23 17:06:37 +0000 Commit: John Baldwin CommitDate: 2023-11-23 17:06:37 +0000 nexus: Use resource_validate_map_request Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D42724 --- sys/arm64/arm64/nexus.c | 18 +++++------------- sys/powerpc/powerpc/nexus.c | 22 +++++----------------- sys/riscv/riscv/nexus.c | 18 +++++------------- sys/x86/x86/nexus.c | 18 +++++------------- 4 files changed, 20 insertions(+), 56 deletions(-) diff --git a/sys/arm64/arm64/nexus.c b/sys/arm64/arm64/nexus.c index dee86bce656a..7c4cb073c2ef 100644 --- a/sys/arm64/arm64/nexus.c +++ b/sys/arm64/arm64/nexus.c @@ -462,7 +462,8 @@ nexus_map_resource(device_t bus, device_t child, int type, struct resource *r, struct resource_map_request *argsp, struct resource_map *map) { struct resource_map_request args; - rman_res_t end, length, start; + rman_res_t length, start; + int error; /* Resources must be active to be mapped. */ if ((rman_get_flags(r) & RF_ACTIVE) == 0) @@ -478,18 +479,9 @@ nexus_map_resource(device_t bus, device_t child, int type, struct resource *r, } resource_init_map_request(&args); - if (argsp != NULL) - bcopy(argsp, &args, imin(argsp->size, args.size)); - start = rman_get_start(r) + args.offset; - if (args.length == 0) - length = rman_get_size(r); - else - length = args.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); + error = resource_validate_map_request(r, argsp, &args, &start, &length); + if (error) + return (error); map->r_vaddr = pmap_mapdev_attr(start, length, args.memattr); map->r_bustag = &memmap_bus; diff --git a/sys/powerpc/powerpc/nexus.c b/sys/powerpc/powerpc/nexus.c index 03f16dfa9de0..c5f460baf44e 100644 --- a/sys/powerpc/powerpc/nexus.c +++ b/sys/powerpc/powerpc/nexus.c @@ -353,9 +353,9 @@ static int nexus_map_resource(device_t bus, device_t child, int type, struct resource *r, struct resource_map_request *argsp, struct resource_map *map) { - struct resource_map_request args; - rman_res_t end, length, start; + rman_res_t length, start; + int error; /* Resources must be active to be mapped. */ if (!(rman_get_flags(r) & RF_ACTIVE)) @@ -371,21 +371,9 @@ nexus_map_resource(device_t bus, device_t child, int type, struct resource *r, } resource_init_map_request(&args); - if (argsp != NULL) - bcopy(argsp, &args, imin(argsp->size, args.size)); - - start = rman_get_start(r) + args.offset; - if (args.length == 0) - length = rman_get_size(r); - else - length = args.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); + error = resource_validate_map_request(r, argsp, &args, &start, &length); + if (error) + return (error); /* * If this is a memory resource, map it into the kernel. diff --git a/sys/riscv/riscv/nexus.c b/sys/riscv/riscv/nexus.c index 2e693e6cf655..936db3e548e9 100644 --- a/sys/riscv/riscv/nexus.c +++ b/sys/riscv/riscv/nexus.c @@ -424,7 +424,8 @@ nexus_map_resource(device_t bus, device_t child, int type, struct resource *r, struct resource_map_request *argsp, struct resource_map *map) { struct resource_map_request args; - rman_res_t end, length, start; + rman_res_t length, start; + int error; /* Resources must be active to be mapped. */ if ((rman_get_flags(r) & RF_ACTIVE) == 0) @@ -440,18 +441,9 @@ nexus_map_resource(device_t bus, device_t child, int type, struct resource *r, } resource_init_map_request(&args); - if (argsp != NULL) - bcopy(argsp, &args, imin(argsp->size, args.size)); - start = rman_get_start(r) + args.offset; - if (args.length == 0) - length = rman_get_size(r); - else - length = args.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); + error = resource_validate_map_request(r, argsp, &args, &start, &length); + if (error) + return (error); map->r_vaddr = pmap_mapdev(start, length); map->r_bustag = &memmap_bus; diff --git a/sys/x86/x86/nexus.c b/sys/x86/x86/nexus.c index 4896271b92bd..54c655c4fafd 100644 --- a/sys/x86/x86/nexus.c +++ b/sys/x86/x86/nexus.c @@ -458,7 +458,8 @@ nexus_map_resource(device_t bus, device_t child, int type, struct resource *r, struct resource_map_request *argsp, struct resource_map *map) { struct resource_map_request args; - rman_res_t end, length, start; + rman_res_t length, start; + int error; /* Resources must be active to be mapped. */ if (!(rman_get_flags(r) & RF_ACTIVE)) @@ -474,18 +475,9 @@ nexus_map_resource(device_t bus, device_t child, int type, struct resource *r, } resource_init_map_request(&args); - if (argsp != NULL) - bcopy(argsp, &args, imin(argsp->size, args.size)); - start = rman_get_start(r) + args.offset; - if (args.length == 0) - length = rman_get_size(r); - else - length = args.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); + error = resource_validate_map_request(r, argsp, &args, &start, &length); + if (error) + return (error); /* * If this is a memory resource, map it into the kernel.