From 6ecfb593db140e81e7af6f81115c9ee4b4c0722a Mon Sep 17 00:00:00 2001 From: Jon Hunter Date: Mon, 22 Jan 2024 14:51:19 +0000 Subject: [PATCH] gpu: nvgpu: Don't use strlcpy() For Linux v6.8, the function strlcpy() has been removed. The function strscpy() was added in Linux v4.3 and has been preferred over strlcpy(). See upstream Linux commit 30035e45753b ("string: provide strscpy()") for more details. The Linux checkpatch.pl script warns against using strlcpy(). The function strscpy() takes the same arguments as strlcpy(), but returns a type of ssize_t instead of size_t. Update the NVGPU to use strscpy() instead of strlcpy(). Bug 4448428 Change-Id: I0464b13720de20288a50375b167740ea514ca130 Signed-off-by: Jon Hunter Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/3059558 (cherry picked from commit 5a12d5469192620e5c5b9e8828c728c148f10425) Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/3062999 Reviewed-by: Brad Griffis GVS: Gerrit_Virtual_Submit --- drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c | 23 +++++++---------------- drivers/gpu/nvgpu/os/linux/pci_power.c | 22 ++++++---------------- 2 files changed, 13 insertions(+), 32 deletions(-) diff --git a/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c b/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c index 45d34aa20..a9a65886b 100644 --- a/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c +++ b/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c @@ -1,18 +1,5 @@ -/* - * Copyright (c) 2011-2023, NVIDIA Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ +// SPDX-License-Identifier: GPL-2.0-only +// SPDX-FileCopyrightText: Copyright (c) 2011-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. #include #include @@ -386,6 +373,7 @@ static long gk20a_ctrl_ioctl_gpu_characteristics( struct nvgpu_gpu_characteristics gpu; long err = 0; struct nvgpu_gpu_instance *gpu_instance; + ssize_t len; u32 gr_instance_id = nvgpu_grmgr_get_gr_instance_id(g, gpu_instance_id); @@ -516,7 +504,10 @@ static long gk20a_ctrl_ioctl_gpu_characteristics( gpu.gpu_va_bit_count = 40; gpu.max_dbg_tsg_timeslice = g->tsg_dbg_timeslice_max_us; - strlcpy(gpu.chipname, g->name, sizeof(gpu.chipname)); + len = strscpy(gpu.chipname, g->name, sizeof(gpu.chipname)); + if (len < 0) + return -ENAMETOOLONG; + gpu.max_fbps_count = nvgpu_grmgr_get_max_fbps_count(g); gpu.fbp_en_mask = nvgpu_grmgr_get_fbp_en_mask(g, gpu_instance_id); gpu.max_ltc_per_fbp = g->ops.top.get_max_ltc_per_fbp(g); diff --git a/drivers/gpu/nvgpu/os/linux/pci_power.c b/drivers/gpu/nvgpu/os/linux/pci_power.c index b0edddc26..6406eb35a 100644 --- a/drivers/gpu/nvgpu/os/linux/pci_power.c +++ b/drivers/gpu/nvgpu/os/linux/pci_power.c @@ -1,18 +1,5 @@ -/* - * Copyright (c) 2018-2020, NVIDIA CORPORATION. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ +// SPDX-License-Identifier: GPL-2.0-only +// SPDX-FileCopyrightText: Copyright (c) 2018-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. #include #include @@ -74,6 +61,7 @@ int nvgpu_pci_add_pci_power(struct pci_dev *pdev) { struct gk20a_platform *platform; struct nvgpu_pci_power *pp; + ssize_t len; if (!pdev) return -EINVAL; @@ -90,8 +78,10 @@ int nvgpu_pci_add_pci_power(struct pci_dev *pdev) nvgpu_mutex_init(&pp->mutex); pp->pci_dev = pdev; - strlcpy(pp->pci_dev_name, + len = strscpy(pp->pci_dev_name, dev_name(&pdev->dev), PCI_DEV_NAME_MAX); + if (len < 0) + return -ENAMETOOLONG; platform = pci_get_drvdata(pdev); pp->can_pci_gc_off = platform->can_pci_gc_off;