]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
Fixes for 6.13
authorSasha Levin <sashal@kernel.org>
Tue, 8 Apr 2025 00:42:37 +0000 (20:42 -0400)
committerSasha Levin <sashal@kernel.org>
Tue, 8 Apr 2025 00:42:37 +0000 (20:42 -0400)
Signed-off-by: Sasha Levin <sashal@kernel.org>
27 files changed:
queue-6.13/arm64-dts-rockchip-add-missing-pcie-supplies-to-rock.patch [new file with mode: 0644]
queue-6.13/drm-amdgpu-gfx11-fix-num_mec.patch [new file with mode: 0644]
queue-6.13/drm-amdgpu-gfx12-fix-num_mec.patch [new file with mode: 0644]
queue-6.13/drm-xe-fix-unmet-direct-dependencies-warning.patch [new file with mode: 0644]
queue-6.13/kbuild-deb-pkg-don-t-set-kbuild_build_version-uncond.patch [new file with mode: 0644]
queue-6.13/perf-core-fix-child_total_time_enabled-accounting-bu.patch [new file with mode: 0644]
queue-6.13/series
queue-6.13/staging-gpib-add-missing-mutex-unlock-in-agilent-usb.patch [new file with mode: 0644]
queue-6.13/staging-gpib-agilent-usb-code-cleanup.patch [new file with mode: 0644]
queue-6.13/staging-gpib-agilent-usb-console-messaging-cleanup.patch [new file with mode: 0644]
queue-6.13/staging-gpib-agilent_82357a-handle-gpib_register_dri.patch [new file with mode: 0644]
queue-6.13/staging-gpib-fix-null-pointer-dereference-in-detach.patch [new file with mode: 0644]
queue-6.13/staging-gpib-fix-oops-after-disconnect-in-agilent-us.patch [new file with mode: 0644]
queue-6.13/staging-gpib-fix-oops-after-disconnect-in-ni_usb.patch [new file with mode: 0644]
queue-6.13/staging-gpib-modify-gpib_register_driver-to-return-e.patch [new file with mode: 0644]
queue-6.13/staging-gpib-ni_usb-console-messaging-cleanup.patch [new file with mode: 0644]
queue-6.13/staging-gpib-ni_usb-handle-gpib_register_driver-erro.patch [new file with mode: 0644]
queue-6.13/staging-gpib-replace-semaphore-with-completion-for-o.patch [new file with mode: 0644]
queue-6.13/tools-power-turbostat-report-corethr-per-measurement.patch [new file with mode: 0644]
queue-6.13/tools-power-turbostat-restore-gfx-sysfs-fflush-call.patch [new file with mode: 0644]
queue-6.13/tracing-correct-the-refcount-if-the-hist-hist_debug-.patch [new file with mode: 0644]
queue-6.13/tracing-hist-add-poll-pollin-support-on-hist-file.patch [new file with mode: 0644]
queue-6.13/tracing-hist-support-pollpri-event-for-poll-on-histo.patch [new file with mode: 0644]
queue-6.13/tracing-switch-trace_events_hist.c-code-over-to-use-.patch [new file with mode: 0644]
queue-6.13/tty-serial-fsl_lpuart-use-port-struct-directly-to-si.patch [new file with mode: 0644]
queue-6.13/tty-serial-fsl_lpuart-use-u32-and-u8-for-register-va.patch [new file with mode: 0644]
queue-6.13/tty-serial-lpuart-only-disable-cts-instead-of-overwr.patch [new file with mode: 0644]

diff --git a/queue-6.13/arm64-dts-rockchip-add-missing-pcie-supplies-to-rock.patch b/queue-6.13/arm64-dts-rockchip-add-missing-pcie-supplies-to-rock.patch
new file mode 100644 (file)
index 0000000..f92def8
--- /dev/null
@@ -0,0 +1,91 @@
+From e674bddb6329f27d249cf9b3bed6126fea405555 Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Sun, 2 Mar 2025 19:48:04 +0100
+Subject: arm64: dts: rockchip: Add missing PCIe supplies to RockPro64 board
+ dtsi
+
+From: Dragan Simic <dsimic@manjaro.org>
+
+[ Upstream commit ffcef3df680c437ca33ff434be18ec24d72907c2 ]
+
+Add missing "vpcie0v9-supply" and "vpcie1v8-supply" properties to the "pcie0"
+node in the Pine64 RockPro64 board dtsi file.  This eliminates the following
+warnings from the kernel log:
+
+  rockchip-pcie f8000000.pcie: supply vpcie1v8 not found, using dummy regulator
+  rockchip-pcie f8000000.pcie: supply vpcie0v9 not found, using dummy regulator
+
+These additions improve the accuracy of hardware description of the RockPro64
+and, in theory, they should result in no functional changes to the way board
+works after the changes, because the "vcca_0v9" and "vcca_1v8" regulators are
+always enabled. [1][2]  However, extended reliability testing, performed by
+Chris, [3] has proven that the age-old issues with some PCI Express cards,
+when used with a Pine64 RockPro64, are also resolved.
+
+Those issues were already mentioned in the commit 43853e843aa6 (arm64: dts:
+rockchip: Remove unsupported node from the Pinebook Pro dts, 2024-04-01),
+together with a brief description of the out-of-tree enumeration delay patch
+that reportedly resolves those issues.  In a nutshell, booting a RockPro64
+with some PCI Express cards attached to it caused a kernel oops. [4]
+
+Symptomatically enough, to the commit author's best knowledge, only the Pine64
+RockPro64, out of all RK3399-based boards and devices supported upstream, has
+been reported to suffer from those PCI Express issues, and only the RockPro64
+had some of the PCI Express supplies missing in its DT.  Thus, perhaps some
+weird timing issues exist that caused the "vcca_1v8" always-on regulator,
+which is part of the RK808 PMIC, to actually not be enabled before the PCI
+Express is initialized and enumerated on the RockPro64, causing oopses with
+some PCIe cards, and the aforementioned enumeration delay patch [4] probably
+acted as just a workaround for the underlying timing issue.
+
+Admittedly, the Pine64 RockPro64 is a bit specific board by having a standard
+PCI Express slot, allowing use of various standard cards, but pretty much
+standard PCI Express cards have been attached to other RK3399 boards as well,
+and the commit author is unaware ot such issues reported for them.
+
+It's quite hard to be sure that the PCI Express issues are fully resolved by
+these additions to the DT, without some really extensive and time-consuming
+testing.  However, these additions to the DT can result in good things and
+improvements anyway, making them perfectly safe from the standpoint of being
+unable to do any harm or cause some unforeseen regressions.
+
+These changes apply to the both supported hardware revisions of the Pine64
+RockPro64, i.e. to the production-run revisions 2.0 and 2.1. [1][2]
+
+[1] https://files.pine64.org/doc/rockpro64/rockpro64_v21-SCH.pdf
+[2] https://files.pine64.org/doc/rockpro64/rockpro64_v20-SCH.pdf
+[3] https://z9.de/hedgedoc/s/nF4d5G7rg#reboot-tests-for-PCIe-improvements
+[4] https://lore.kernel.org/lkml/20230509153912.515218-1-vincenzopalazzodev@gmail.com/T/#u
+
+Fixes: bba821f5479e ("arm64: dts: rockchip: add PCIe nodes on rk3399-rockpro64")
+Cc: stable@vger.kernel.org
+Cc: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
+Cc: Peter Geis <pgwipeout@gmail.com>
+Cc: Bjorn Helgaas <helgaas@kernel.org>
+Reported-by: Diederik de Haas <didi.debian@cknow.org>
+Tested-by: Chris Vogel <chris@z9.de>
+Signed-off-by: Dragan Simic <dsimic@manjaro.org>
+Tested-by: Diederik de Haas <didi.debian@cknow.org>
+Link: https://lore.kernel.org/r/b39cfd7490d8194f053bf3971f13a43472d1769e.1740941097.git.dsimic@manjaro.org
+Signed-off-by: Heiko Stuebner <heiko@sntech.de>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ arch/arm64/boot/dts/rockchip/rk3399-rockpro64.dtsi | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/arch/arm64/boot/dts/rockchip/rk3399-rockpro64.dtsi b/arch/arm64/boot/dts/rockchip/rk3399-rockpro64.dtsi
+index 47dc198706c85..51c6aa26d8285 100644
+--- a/arch/arm64/boot/dts/rockchip/rk3399-rockpro64.dtsi
++++ b/arch/arm64/boot/dts/rockchip/rk3399-rockpro64.dtsi
+@@ -673,6 +673,8 @@ &pcie0 {
+       num-lanes = <4>;
+       pinctrl-names = "default";
+       pinctrl-0 = <&pcie_perst>;
++      vpcie0v9-supply = <&vcca_0v9>;
++      vpcie1v8-supply = <&vcca_1v8>;
+       vpcie12v-supply = <&vcc12v_dcin>;
+       vpcie3v3-supply = <&vcc3v3_pcie>;
+       status = "okay";
+-- 
+2.39.5
+
diff --git a/queue-6.13/drm-amdgpu-gfx11-fix-num_mec.patch b/queue-6.13/drm-amdgpu-gfx11-fix-num_mec.patch
new file mode 100644 (file)
index 0000000..bee0c86
--- /dev/null
@@ -0,0 +1,35 @@
+From b2ff181b877630760c46539352678fda71d4d694 Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Wed, 26 Mar 2025 09:35:02 -0400
+Subject: drm/amdgpu/gfx11: fix num_mec
+
+From: Alex Deucher <alexander.deucher@amd.com>
+
+[ Upstream commit 4161050d47e1b083a7e1b0b875c9907e1a6f1f1f ]
+
+GC11 only has 1 mec.
+
+Fixes: 3d879e81f0f9 ("drm/amdgpu: add init support for GFX11 (v2)")
+Reviewed-by: Sunil Khatri <sunil.khatri@amd.com>
+Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
+index 2ae058a224f4d..a24119b386db1 100644
+--- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
++++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
+@@ -1553,7 +1553,7 @@ static int gfx_v11_0_sw_init(struct amdgpu_ip_block *ip_block)
+               adev->gfx.me.num_me = 1;
+               adev->gfx.me.num_pipe_per_me = 1;
+               adev->gfx.me.num_queue_per_pipe = 1;
+-              adev->gfx.mec.num_mec = 2;
++              adev->gfx.mec.num_mec = 1;
+               adev->gfx.mec.num_pipe_per_mec = 4;
+               adev->gfx.mec.num_queue_per_pipe = 4;
+               break;
+-- 
+2.39.5
+
diff --git a/queue-6.13/drm-amdgpu-gfx12-fix-num_mec.patch b/queue-6.13/drm-amdgpu-gfx12-fix-num_mec.patch
new file mode 100644 (file)
index 0000000..a4cb69c
--- /dev/null
@@ -0,0 +1,35 @@
+From 0ec32cd8f55f548259c8977c11952807a7836580 Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Thu, 20 Mar 2025 12:09:11 -0400
+Subject: drm/amdgpu/gfx12: fix num_mec
+
+From: Alex Deucher <alexander.deucher@amd.com>
+
+[ Upstream commit dce8bd9137b88735dd0efc4e2693213d98c15913 ]
+
+GC12 only has 1 mec.
+
+Fixes: 52cb80c12e8a ("drm/amdgpu: Add gfx v12_0 ip block support (v6)")
+Reviewed-by: Sunil Khatri <sunil.khatri@amd.com>
+Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
+index d4218e9e43b56..a0df3baaf2b40 100644
+--- a/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
++++ b/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
+@@ -1332,7 +1332,7 @@ static int gfx_v12_0_sw_init(struct amdgpu_ip_block *ip_block)
+               adev->gfx.me.num_me = 1;
+               adev->gfx.me.num_pipe_per_me = 1;
+               adev->gfx.me.num_queue_per_pipe = 1;
+-              adev->gfx.mec.num_mec = 2;
++              adev->gfx.mec.num_mec = 1;
+               adev->gfx.mec.num_pipe_per_mec = 2;
+               adev->gfx.mec.num_queue_per_pipe = 4;
+               break;
+-- 
+2.39.5
+
diff --git a/queue-6.13/drm-xe-fix-unmet-direct-dependencies-warning.patch b/queue-6.13/drm-xe-fix-unmet-direct-dependencies-warning.patch
new file mode 100644 (file)
index 0000000..a115b3d
--- /dev/null
@@ -0,0 +1,46 @@
+From 1b219817f47ed549269d188f36e8c6f658b77afa Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Sun, 23 Mar 2025 19:41:03 +0800
+Subject: drm/xe: Fix unmet direct dependencies warning
+
+From: Yue Haibing <yuehaibing@huawei.com>
+
+[ Upstream commit 5e66cf6edddb5f6237e3afb07475ace57ecb56bc ]
+
+WARNING: unmet direct dependencies detected for FB_IOMEM_HELPERS
+  Depends on [n]: HAS_IOMEM [=y] && FB_CORE [=n]
+  Selected by [m]:
+  - DRM_XE_DISPLAY [=y] && HAS_IOMEM [=y] && DRM [=m] && DRM_XE [=m] && DRM_XE [=m]=m [=m] && HAS_IOPORT [=y]
+
+DRM_XE_DISPLAY requires FB_IOMEM_HELPERS, but the dependency FB_CORE is
+missing, selecting FB_IOMEM_HELPERS if DRM_FBDEV_EMULATION is set as
+other drm drivers.
+
+Fixes: 44e694958b95 ("drm/xe/display: Implement display support")
+Signed-off-by: Yue Haibing <yuehaibing@huawei.com>
+Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
+Link: https://patchwork.freedesktop.org/patch/msgid/20250323114103.1960511-1-yuehaibing@huawei.com
+Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
+(cherry picked from commit 689582882802cd64986c1eb584c9f5184d67f0cf)
+Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ drivers/gpu/drm/xe/Kconfig | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/drivers/gpu/drm/xe/Kconfig b/drivers/gpu/drm/xe/Kconfig
+index b51a2bde73e29..dcf6583a4c522 100644
+--- a/drivers/gpu/drm/xe/Kconfig
++++ b/drivers/gpu/drm/xe/Kconfig
+@@ -52,7 +52,7 @@ config DRM_XE
+ config DRM_XE_DISPLAY
+       bool "Enable display support"
+       depends on DRM_XE && DRM_XE=m && HAS_IOPORT
+-      select FB_IOMEM_HELPERS
++      select FB_IOMEM_HELPERS if DRM_FBDEV_EMULATION
+       select I2C
+       select I2C_ALGOBIT
+       default y
+-- 
+2.39.5
+
diff --git a/queue-6.13/kbuild-deb-pkg-don-t-set-kbuild_build_version-uncond.patch b/queue-6.13/kbuild-deb-pkg-don-t-set-kbuild_build_version-uncond.patch
new file mode 100644 (file)
index 0000000..4171776
--- /dev/null
@@ -0,0 +1,64 @@
+From 915d67b5521c613eff639d5977a8c9a59d20fa67 Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Fri, 14 Mar 2025 13:10:53 +0000
+Subject: kbuild: deb-pkg: don't set KBUILD_BUILD_VERSION unconditionally
+
+From: Alexandru Gagniuc <alexandru.gagniuc@hp.com>
+
+[ Upstream commit 62604063621fb075c7966286bdddcb057d883fa8 ]
+
+In ThinPro, we use the convention <upstream_ver>+hp<patchlevel> for
+the kernel package. This does not have a dash in the name or version.
+This is built by editing ".version" before a build, and setting
+EXTRAVERSION="+hp" and KDEB_PKGVERSION make variables:
+
+    echo 68 > .version
+    make -j<n> EXTRAVERSION="+hp" bindeb-pkg KDEB_PKGVERSION=6.12.2+hp69
+
+    .deb name: linux-image-6.12.2+hp_6.12.2+hp69_amd64.deb
+
+Since commit 7d4f07d5cb71 ("kbuild: deb-pkg: squash
+scripts/package/deb-build-option to debian/rules"), this no longer
+works. The deb build logic changed, even though, the commit message
+implies that the logic should be unmodified.
+
+Before, KBUILD_BUILD_VERSION was not set if the KDEB_PKGVERSION did
+not contain a dash. After the change KBUILD_BUILD_VERSION is always
+set to KDEB_PKGVERSION. Since this determines UTS_VERSION, the uname
+output to look off:
+
+    (now)      uname -a: version 6.12.2+hp ... #6.12.2+hp69
+    (expected) uname -a: version 6.12.2+hp ... #69
+
+Update the debian/rules logic to restore the original behavior.
+
+Fixes: 7d4f07d5cb71 ("kbuild: deb-pkg: squash scripts/package/deb-build-option to debian/rules")
+Signed-off-by: Alexandru Gagniuc <alexandru.gagniuc@hp.com>
+Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
+Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ scripts/package/debian/rules | 6 ++++--
+ 1 file changed, 4 insertions(+), 2 deletions(-)
+
+diff --git a/scripts/package/debian/rules b/scripts/package/debian/rules
+index ca07243bd5cdf..2b3f9a0bd6c40 100755
+--- a/scripts/package/debian/rules
++++ b/scripts/package/debian/rules
+@@ -21,9 +21,11 @@ ifeq ($(origin KBUILD_VERBOSE),undefined)
+     endif
+ endif
+-revision = $(lastword $(subst -, ,$(shell dpkg-parsechangelog -S Version)))
++revision = $(shell dpkg-parsechangelog -S Version | sed -n 's/.*-//p')
+ CROSS_COMPILE ?= $(filter-out $(DEB_BUILD_GNU_TYPE)-, $(DEB_HOST_GNU_TYPE)-)
+-make-opts = ARCH=$(ARCH) KERNELRELEASE=$(KERNELRELEASE) KBUILD_BUILD_VERSION=$(revision) $(addprefix CROSS_COMPILE=,$(CROSS_COMPILE))
++make-opts = ARCH=$(ARCH) KERNELRELEASE=$(KERNELRELEASE) \
++    $(addprefix KBUILD_BUILD_VERSION=,$(revision)) \
++    $(addprefix CROSS_COMPILE=,$(CROSS_COMPILE))
+ binary-targets := $(addprefix binary-, image image-dbg headers libc-dev)
+-- 
+2.39.5
+
diff --git a/queue-6.13/perf-core-fix-child_total_time_enabled-accounting-bu.patch b/queue-6.13/perf-core-fix-child_total_time_enabled-accounting-bu.patch
new file mode 100644 (file)
index 0000000..d1d5c50
--- /dev/null
@@ -0,0 +1,143 @@
+From 677176ab8e644aabb93972b81d137e5cf289d446 Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Wed, 26 Mar 2025 08:20:03 +0000
+Subject: perf/core: Fix child_total_time_enabled accounting bug at task exit
+
+From: Yeoreum Yun <yeoreum.yun@arm.com>
+
+[ Upstream commit a3c3c66670cee11eb13aa43905904bf29cb92d32 ]
+
+The perf events code fails to account for total_time_enabled of
+inactive events.
+
+Here is a failure case for accounting total_time_enabled for
+CPU PMU events:
+
+  sudo ./perf stat -vvv -e armv8_pmuv3_0/event=0x08/ -e armv8_pmuv3_1/event=0x08/ -- stress-ng --pthread=2 -t 2s
+  ...
+
+  armv8_pmuv3_0/event=0x08/: 1138698008 2289429840 2174835740
+  armv8_pmuv3_1/event=0x08/: 1826791390 1950025700 847648440
+                             `          `          `
+                             `          `          > total_time_running with child
+                             `          > total_time_enabled with child
+                             > count with child
+
+  Performance counter stats for 'stress-ng --pthread=2 -t 2s':
+
+       1,138,698,008      armv8_pmuv3_0/event=0x08/                                               (94.99%)
+       1,826,791,390      armv8_pmuv3_1/event=0x08/                                               (43.47%)
+
+The two events above are opened on two different CPU PMUs, for example,
+each event is opened for a cluster in an Arm big.LITTLE system, they
+will never run on the same CPU.  In theory, the total enabled time should
+be same for both events, as two events are opened and closed together.
+
+As the result show, the two events' total enabled time including
+child event is different (2289429840 vs 1950025700).
+
+This is because child events are not accounted properly
+if a event is INACTIVE state when the task exits:
+
+  perf_event_exit_event()
+   `> perf_remove_from_context()
+     `> __perf_remove_from_context()
+       `> perf_child_detach()   -> Accumulate child_total_time_enabled
+         `> list_del_event()    -> Update child event's time
+
+The problem is the time accumulation happens prior to child event's
+time updating. Thus, it misses to account the last period's time when
+the event exits.
+
+The perf core layer follows the rule that timekeeping is tied to state
+change. To address the issue, make __perf_remove_from_context()
+handle the task exit case by passing 'DETACH_EXIT' to it and
+invoke perf_event_state() for state alongside with accounting the time.
+
+Then, perf_child_detach() populates the time into the parent's time metrics.
+
+After this patch, the bug is fixed:
+
+  sudo ./perf stat -vvv -e armv8_pmuv3_0/event=0x08/ -e armv8_pmuv3_1/event=0x08/ -- stress-ng --pthread=2 -t 10s
+  ...
+  armv8_pmuv3_0/event=0x08/: 15396770398 32157963940 21898169000
+  armv8_pmuv3_1/event=0x08/: 22428964974 32157963940 10259794940
+
+   Performance counter stats for 'stress-ng --pthread=2 -t 10s':
+
+      15,396,770,398      armv8_pmuv3_0/event=0x08/                                               (68.10%)
+      22,428,964,974      armv8_pmuv3_1/event=0x08/                                               (31.90%)
+
+[ mingo: Clarified the changelog. ]
+
+Fixes: ef54c1a476aef ("perf: Rework perf_event_exit_event()")
+Suggested-by: Peter Zijlstra <peterz@infradead.org>
+Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
+Signed-off-by: Ingo Molnar <mingo@kernel.org>
+Tested-by: Leo Yan <leo.yan@arm.com>
+Link: https://lore.kernel.org/r/20250326082003.1630986-1-yeoreum.yun@arm.com
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ kernel/events/core.c | 18 +++++++++---------
+ 1 file changed, 9 insertions(+), 9 deletions(-)
+
+diff --git a/kernel/events/core.c b/kernel/events/core.c
+index 1cecf092db808..2d2ff7ca95a5b 100644
+--- a/kernel/events/core.c
++++ b/kernel/events/core.c
+@@ -2407,6 +2407,7 @@ ctx_time_update_event(struct perf_event_context *ctx, struct perf_event *event)
+ #define DETACH_GROUP  0x01UL
+ #define DETACH_CHILD  0x02UL
+ #define DETACH_DEAD   0x04UL
++#define DETACH_EXIT   0x08UL
+ /*
+  * Cross CPU call to remove a performance event
+@@ -2421,6 +2422,7 @@ __perf_remove_from_context(struct perf_event *event,
+                          void *info)
+ {
+       struct perf_event_pmu_context *pmu_ctx = event->pmu_ctx;
++      enum perf_event_state state = PERF_EVENT_STATE_OFF;
+       unsigned long flags = (unsigned long)info;
+       ctx_time_update(cpuctx, ctx);
+@@ -2429,16 +2431,19 @@ __perf_remove_from_context(struct perf_event *event,
+        * Ensure event_sched_out() switches to OFF, at the very least
+        * this avoids raising perf_pending_task() at this time.
+        */
+-      if (flags & DETACH_DEAD)
++      if (flags & DETACH_EXIT)
++              state = PERF_EVENT_STATE_EXIT;
++      if (flags & DETACH_DEAD) {
+               event->pending_disable = 1;
++              state = PERF_EVENT_STATE_DEAD;
++      }
+       event_sched_out(event, ctx);
++      perf_event_set_state(event, min(event->state, state));
+       if (flags & DETACH_GROUP)
+               perf_group_detach(event);
+       if (flags & DETACH_CHILD)
+               perf_child_detach(event);
+       list_del_event(event, ctx);
+-      if (flags & DETACH_DEAD)
+-              event->state = PERF_EVENT_STATE_DEAD;
+       if (!pmu_ctx->nr_events) {
+               pmu_ctx->rotate_necessary = 0;
+@@ -13405,12 +13410,7 @@ perf_event_exit_event(struct perf_event *event, struct perf_event_context *ctx)
+               mutex_lock(&parent_event->child_mutex);
+       }
+-      perf_remove_from_context(event, detach_flags);
+-
+-      raw_spin_lock_irq(&ctx->lock);
+-      if (event->state > PERF_EVENT_STATE_EXIT)
+-              perf_event_set_state(event, PERF_EVENT_STATE_EXIT);
+-      raw_spin_unlock_irq(&ctx->lock);
++      perf_remove_from_context(event, detach_flags | DETACH_EXIT);
+       /*
+        * Child events can be freed.
+-- 
+2.39.5
+
index a06e1a4b85ed33fe48fbbdecd17f411c92384cc3..e68fbeca1cfa76c51cbd457dd8c74645fa947023 100644 (file)
@@ -404,3 +404,29 @@ ipv6-start-path-selection-from-the-first-nexthop.patch
 ipv6-do-not-consider-link-down-nexthops-in-path-sele.patch
 arcnet-add-null-check-in-com20020pci_probe.patch
 net-ibmveth-make-veth_pool_store-stop-hanging.patch
+kbuild-deb-pkg-don-t-set-kbuild_build_version-uncond.patch
+drm-xe-fix-unmet-direct-dependencies-warning.patch
+drm-amdgpu-gfx11-fix-num_mec.patch
+drm-amdgpu-gfx12-fix-num_mec.patch
+perf-core-fix-child_total_time_enabled-accounting-bu.patch
+tools-power-turbostat-report-corethr-per-measurement.patch
+tools-power-turbostat-restore-gfx-sysfs-fflush-call.patch
+tracing-switch-trace_events_hist.c-code-over-to-use-.patch
+tracing-hist-add-poll-pollin-support-on-hist-file.patch
+tracing-hist-support-pollpri-event-for-poll-on-histo.patch
+tracing-correct-the-refcount-if-the-hist-hist_debug-.patch
+arm64-dts-rockchip-add-missing-pcie-supplies-to-rock.patch
+staging-gpib-replace-semaphore-with-completion-for-o.patch
+staging-gpib-modify-gpib_register_driver-to-return-e.patch
+staging-gpib-ni_usb-handle-gpib_register_driver-erro.patch
+staging-gpib-ni_usb-console-messaging-cleanup.patch
+staging-gpib-fix-oops-after-disconnect-in-ni_usb.patch
+staging-gpib-agilent_82357a-handle-gpib_register_dri.patch
+staging-gpib-add-missing-mutex-unlock-in-agilent-usb.patch
+staging-gpib-fix-null-pointer-dereference-in-detach.patch
+staging-gpib-agilent-usb-code-cleanup.patch
+staging-gpib-agilent-usb-console-messaging-cleanup.patch
+staging-gpib-fix-oops-after-disconnect-in-agilent-us.patch
+tty-serial-fsl_lpuart-use-u32-and-u8-for-register-va.patch
+tty-serial-fsl_lpuart-use-port-struct-directly-to-si.patch
+tty-serial-lpuart-only-disable-cts-instead-of-overwr.patch
diff --git a/queue-6.13/staging-gpib-add-missing-mutex-unlock-in-agilent-usb.patch b/queue-6.13/staging-gpib-add-missing-mutex-unlock-in-agilent-usb.patch
new file mode 100644 (file)
index 0000000..d7e4c80
--- /dev/null
@@ -0,0 +1,46 @@
+From 0d920d729002b697d5e5b1f949391321a3bd57da Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Sat, 11 Jan 2025 17:14:57 +0100
+Subject: staging: gpib: Add missing mutex unlock in agilent usb driver
+
+From: Dave Penkler <dpenkler@gmail.com>
+
+[ Upstream commit 55eb3c3a6388420afda1374b353717de32ae9573 ]
+
+When no matching product id was found in the attach function the driver
+returned without unlocking the agilent_82357a_hotplug_lock mutex.
+
+Add the unlock call.
+
+This was detected by smatch:
+smatch warnings:
+drivers/staging/gpib/agilent_82357a/agilent_82357a.c:1381 agilent_82357a_attach() warn: inconsistent returns 'global &agilent_82357a_hotplug_lock'.
+
+Reported-by: kernel test robot <lkp@intel.com>
+Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
+Closes: https://lore.kernel.org/r/202412210143.WJhYzXfD-lkp@intel.com/
+Fixes: 4c41fe886a56 ("staging: gpib: Add Agilent/Keysight 82357x USB GPIB driver")
+Signed-off-by: Dave Penkler <dpenkler@gmail.com>
+Link: https://lore.kernel.org/r/20250111161457.27556-1-dpenkler@gmail.com
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Stable-dep-of: 8491e73a5223 ("staging: gpib: Fix Oops after disconnect in agilent usb")
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ drivers/staging/gpib/agilent_82357a/agilent_82357a.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/drivers/staging/gpib/agilent_82357a/agilent_82357a.c b/drivers/staging/gpib/agilent_82357a/agilent_82357a.c
+index 261fb6d2e9916..942ab663e4001 100644
+--- a/drivers/staging/gpib/agilent_82357a/agilent_82357a.c
++++ b/drivers/staging/gpib/agilent_82357a/agilent_82357a.c
+@@ -1365,6 +1365,7 @@ static int agilent_82357a_attach(gpib_board_t *board, const gpib_board_config_t
+               break;
+       default:
+               dev_err(&usb_dev->dev, "bug, unhandled product_id in switch?\n");
++              mutex_unlock(&agilent_82357a_hotplug_lock);
+               return -EIO;
+       }
+ #ifdef RESET_USB_CONFIG
+-- 
+2.39.5
+
diff --git a/queue-6.13/staging-gpib-agilent-usb-code-cleanup.patch b/queue-6.13/staging-gpib-agilent-usb-code-cleanup.patch
new file mode 100644 (file)
index 0000000..795ff5f
--- /dev/null
@@ -0,0 +1,189 @@
+From 4a805da79c0246074d40d0ef854d8e5def4c344b Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Sat, 18 Jan 2025 15:50:46 +0100
+Subject: staging: gpib: Agilent usb code cleanup
+
+From: Dave Penkler <dpenkler@gmail.com>
+
+[ Upstream commit 579b6f18c5ca162af040f44684cc55f7da182236 ]
+
+Remove useless #ifdef RESET_USB_CONFIG code.
+
+Change kalloc / memset to kzalloc
+
+The attach function was not freeing the private data on error
+returns. Separate the releasing of urbs and private data and
+add a common error exit for attach failure.
+
+Set the board private data pointer to NULL after freeing
+the private data.
+
+Reduce console spam by emitting only one attach message.
+
+Change last pr_err in attach to dev_err
+
+Signed-off-by: Dave Penkler <dpenkler@gmail.com>
+Link: https://lore.kernel.org/r/20250118145046.12181-3-dpenkler@gmail.com
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Stable-dep-of: 8491e73a5223 ("staging: gpib: Fix Oops after disconnect in agilent usb")
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ .../gpib/agilent_82357a/agilent_82357a.c      | 84 ++++++++-----------
+ 1 file changed, 36 insertions(+), 48 deletions(-)
+
+diff --git a/drivers/staging/gpib/agilent_82357a/agilent_82357a.c b/drivers/staging/gpib/agilent_82357a/agilent_82357a.c
+index d072c63651629..0d8d495d3dfc6 100644
+--- a/drivers/staging/gpib/agilent_82357a/agilent_82357a.c
++++ b/drivers/staging/gpib/agilent_82357a/agilent_82357a.c
+@@ -1146,25 +1146,6 @@ static int agilent_82357a_setup_urbs(gpib_board_t *board)
+       return retval;
+ }
+-#ifdef RESET_USB_CONFIG
+-static int agilent_82357a_reset_usb_configuration(gpib_board_t *board)
+-{
+-      struct agilent_82357a_priv *a_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(a_priv->bus_interface);
+-      struct usb_device *usb_dev;
+-      int retval;
+-
+-      if (!a_priv->bus_interface)
+-              return -ENODEV;
+-      usb_dev = interface_to_usbdev(a_priv->bus_interface);
+-      retval = usb_reset_configuration(usb_dev);
+-      if (retval)
+-              dev_err(&usb_dev->dev, "%s: usb_reset_configuration() returned %i\n",
+-                      __func__, retval);
+-      return retval;
+-}
+-#endif
+-
+ static void agilent_82357a_cleanup_urbs(struct agilent_82357a_priv *a_priv)
+ {
+       if (a_priv && a_priv->bus_interface) {
+@@ -1175,15 +1156,23 @@ static void agilent_82357a_cleanup_urbs(struct agilent_82357a_priv *a_priv)
+       }
+ };
++static void agilent_82357a_release_urbs(struct agilent_82357a_priv *a_priv)
++{
++      if (a_priv) {
++              usb_free_urb(a_priv->interrupt_urb);
++              a_priv->interrupt_urb = NULL;
++              kfree(a_priv->interrupt_buffer);
++      }
++}
++
+ static int agilent_82357a_allocate_private(gpib_board_t *board)
+ {
+       struct agilent_82357a_priv *a_priv;
+-      board->private_data = kmalloc(sizeof(struct agilent_82357a_priv), GFP_KERNEL);
++      board->private_data = kzalloc(sizeof(struct agilent_82357a_priv), GFP_KERNEL);
+       if (!board->private_data)
+               return -ENOMEM;
+       a_priv = board->private_data;
+-      memset(a_priv, 0, sizeof(struct agilent_82357a_priv));
+       mutex_init(&a_priv->bulk_transfer_lock);
+       mutex_init(&a_priv->bulk_alloc_lock);
+       mutex_init(&a_priv->control_alloc_lock);
+@@ -1191,11 +1180,11 @@ static int agilent_82357a_allocate_private(gpib_board_t *board)
+       return 0;
+ }
+-static void agilent_82357a_free_private(struct agilent_82357a_priv *a_priv)
++static void agilent_82357a_free_private(gpib_board_t *board)
+ {
+-      usb_free_urb(a_priv->interrupt_urb);
+-      kfree(a_priv->interrupt_buffer);
+-      kfree(a_priv);
++      kfree(board->private_data);
++      board->private_data = NULL;
++
+ }
+ static int agilent_82357a_init(gpib_board_t *board)
+@@ -1342,16 +1331,14 @@ static int agilent_82357a_attach(gpib_board_t *board, const gpib_board_config_t
+                       a_priv->bus_interface = agilent_82357a_driver_interfaces[i];
+                       usb_set_intfdata(agilent_82357a_driver_interfaces[i], board);
+                       usb_dev = interface_to_usbdev(a_priv->bus_interface);
+-                      dev_info(&usb_dev->dev,
+-                               "bus %d dev num %d attached to gpib minor %d, agilent usb interface %i\n",
+-                               usb_dev->bus->busnum, usb_dev->devnum, board->minor, i);
+                       break;
+               }
+       }
+       if (i == MAX_NUM_82357A_INTERFACES) {
+-              mutex_unlock(&agilent_82357a_hotplug_lock);
+-              pr_err("No Agilent 82357 gpib adapters found, have you loaded its firmware?\n");
+-              return -ENODEV;
++              dev_err(board->gpib_dev,
++                      "No Agilent 82357 gpib adapters found, have you loaded its firmware?\n");
++              retval = -ENODEV;
++              goto attach_fail;
+       }
+       product_id = le16_to_cpu(interface_to_usbdev(a_priv->bus_interface)->descriptor.idProduct);
+       switch (product_id) {
+@@ -1365,21 +1352,13 @@ static int agilent_82357a_attach(gpib_board_t *board, const gpib_board_config_t
+               break;
+       default:
+               dev_err(&usb_dev->dev, "bug, unhandled product_id in switch?\n");
+-              mutex_unlock(&agilent_82357a_hotplug_lock);
+-              return -EIO;
+-      }
+-#ifdef RESET_USB_CONFIG
+-      retval = agilent_82357a_reset_usb_configuration(board);
+-      if (retval < 0) {
+-              mutex_unlock(&agilent_82357a_hotplug_lock);
+-              return retval;
++              retval = -EIO;
++              goto attach_fail;
+       }
+-#endif
++
+       retval = agilent_82357a_setup_urbs(board);
+-      if (retval < 0) {
+-              mutex_unlock(&agilent_82357a_hotplug_lock);
+-              return retval;
+-      }
++      if (retval < 0)
++              goto attach_fail;
+       timer_setup(&a_priv->bulk_timer, agilent_82357a_timeout_handler, 0);
+@@ -1388,11 +1367,19 @@ static int agilent_82357a_attach(gpib_board_t *board, const gpib_board_config_t
+       retval = agilent_82357a_init(board);
+       if (retval < 0) {
+-              mutex_unlock(&agilent_82357a_hotplug_lock);
+-              return retval;
++              agilent_82357a_cleanup_urbs(a_priv);
++              agilent_82357a_release_urbs(a_priv);
++              goto attach_fail;
+       }
+-      dev_info(&usb_dev->dev, "%s: attached\n", __func__);
++      dev_info(&usb_dev->dev,
++               "bus %d dev num %d attached to gpib minor %d, agilent usb interface %i\n",
++               usb_dev->bus->busnum, usb_dev->devnum, board->minor, i);
++      mutex_unlock(&agilent_82357a_hotplug_lock);
++      return retval;
++
++attach_fail:
++      agilent_82357a_free_private(board);
+       mutex_unlock(&agilent_82357a_hotplug_lock);
+       return retval;
+ }
+@@ -1455,7 +1442,8 @@ static void agilent_82357a_detach(gpib_board_t *board)
+               mutex_lock(&a_priv->bulk_alloc_lock);
+               mutex_lock(&a_priv->interrupt_alloc_lock);
+               agilent_82357a_cleanup_urbs(a_priv);
+-              agilent_82357a_free_private(a_priv);
++              agilent_82357a_release_urbs(a_priv);
++              agilent_82357a_free_private(board);
+       }
+       dev_info(board->gpib_dev, "%s: detached\n", __func__);
+       mutex_unlock(&agilent_82357a_hotplug_lock);
+-- 
+2.39.5
+
diff --git a/queue-6.13/staging-gpib-agilent-usb-console-messaging-cleanup.patch b/queue-6.13/staging-gpib-agilent-usb-console-messaging-cleanup.patch
new file mode 100644 (file)
index 0000000..5114f5e
--- /dev/null
@@ -0,0 +1,868 @@
+From 30ae7c50a8d850ad9ca82f85904f937a3fffeaf6 Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Fri, 14 Feb 2025 12:46:53 +0100
+Subject: staging: gpib: agilent usb console messaging cleanup
+
+From: Dave Penkler <dpenkler@gmail.com>
+
+[ Upstream commit 50a6ed0494bc082227c38f427b40731bca9bdf15 ]
+
+Enable module name to be printed in pr_xxx and dev_xxx
+Use DRV_NAME defined as KBUILD_MODNAME instead of hard coded
+string in usb_driver struct.
+
+Remove __func__ parameter in dev_dbg messages as this can be
+enabled with dynamic debug.
+
+Remove __func__ parameter in dev_err messages as they are not
+needed. The module name is sufficient.
+
+Change pr_info to dev_dbg where needed and remove the rest
+where possible.
+
+Remove test and error messages for buffer over run in write and
+read_registers as these are just trying to catch bugs in the driver.
+
+Remove agilent_82357a string prefix in error messages.
+
+Return -EIO for too many reads in read_registers instead of
+continuing after printing an error message.
+
+Change pr_warn to dev_warn.
+
+Remove warning on calls for unsupported functionality.
+
+Remove test and message for buffer overflow in agilent_82357_init
+and agilent_82357a_go_idle which are just checking for a driver bug.
+Use actual indeces in the array instead of i and then incrementing
+i so that the code is clear and there is no need to check for
+overflow or print a message.
+
+Signed-off-by: Dave Penkler <dpenkler@gmail.com>
+Link: https://lore.kernel.org/r/20250214114708.28947-3-dpenkler@gmail.com
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Stable-dep-of: 8491e73a5223 ("staging: gpib: Fix Oops after disconnect in agilent usb")
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ .../gpib/agilent_82357a/agilent_82357a.c      | 359 +++++++-----------
+ 1 file changed, 143 insertions(+), 216 deletions(-)
+
+diff --git a/drivers/staging/gpib/agilent_82357a/agilent_82357a.c b/drivers/staging/gpib/agilent_82357a/agilent_82357a.c
+index 0d8d495d3dfc6..7a39056ebc886 100644
+--- a/drivers/staging/gpib/agilent_82357a/agilent_82357a.c
++++ b/drivers/staging/gpib/agilent_82357a/agilent_82357a.c
+@@ -7,6 +7,10 @@
+ #define _GNU_SOURCE
++#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
++#define dev_fmt pr_fmt
++#define DRV_NAME KBUILD_MODNAME
++
+ #include <linux/kernel.h>
+ #include <linux/module.h>
+ #include <linux/slab.h>
+@@ -79,14 +83,12 @@ static int agilent_82357a_send_bulk_msg(struct agilent_82357a_priv *a_priv, void
+       retval = usb_submit_urb(a_priv->bulk_urb, GFP_KERNEL);
+       if (retval) {
+-              dev_err(&usb_dev->dev, "%s: failed to submit bulk out urb, retval=%i\n",
+-                      __func__, retval);
++              dev_err(&usb_dev->dev, "failed to submit bulk out urb, retval=%i\n", retval);
+               mutex_unlock(&a_priv->bulk_alloc_lock);
+               goto cleanup;
+       }
+       mutex_unlock(&a_priv->bulk_alloc_lock);
+       if (down_interruptible(&context->complete)) {
+-              dev_err(&usb_dev->dev, "%s: interrupted\n", __func__);
+               retval = -ERESTARTSYS;
+               goto cleanup;
+       }
+@@ -149,14 +151,12 @@ static int agilent_82357a_receive_bulk_msg(struct agilent_82357a_priv *a_priv, v
+       retval = usb_submit_urb(a_priv->bulk_urb, GFP_KERNEL);
+       if (retval) {
+-              dev_err(&usb_dev->dev, "%s: failed to submit bulk out urb, retval=%i\n",
+-                      __func__, retval);
++              dev_err(&usb_dev->dev, "failed to submit bulk in urb, retval=%i\n", retval);
+               mutex_unlock(&a_priv->bulk_alloc_lock);
+               goto cleanup;
+       }
+       mutex_unlock(&a_priv->bulk_alloc_lock);
+       if (down_interruptible(&context->complete)) {
+-              dev_err(&usb_dev->dev, "%s: interrupted\n", __func__);
+               retval = -ERESTARTSYS;
+               goto cleanup;
+       }
+@@ -205,7 +205,6 @@ static int agilent_82357a_receive_control_msg(struct agilent_82357a_priv *a_priv
+ static void agilent_82357a_dump_raw_block(const u8 *raw_data, int length)
+ {
+-      pr_info("hex block dump\n");
+       print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 8, 1, raw_data, length, true);
+ }
+@@ -225,7 +224,7 @@ static int agilent_82357a_write_registers(struct agilent_82357a_priv *a_priv,
+       static const int max_writes = 31;
+       if (num_writes > max_writes) {
+-              dev_err(&usb_dev->dev, "%s: bug! num_writes=%i too large\n", __func__, num_writes);
++              dev_err(&usb_dev->dev, "bug! num_writes=%i too large\n", num_writes);
+               return -EIO;
+       }
+       out_data_length = num_writes * bytes_per_write + header_length;
+@@ -239,8 +238,7 @@ static int agilent_82357a_write_registers(struct agilent_82357a_priv *a_priv,
+               out_data[i++] = writes[j].address;
+               out_data[i++] = writes[j].value;
+       }
+-      if (i > out_data_length)
+-              dev_err(&usb_dev->dev, "%s: bug! buffer overrun\n", __func__);
++
+       retval = mutex_lock_interruptible(&a_priv->bulk_transfer_lock);
+       if (retval) {
+               kfree(out_data);
+@@ -249,8 +247,8 @@ static int agilent_82357a_write_registers(struct agilent_82357a_priv *a_priv,
+       retval = agilent_82357a_send_bulk_msg(a_priv, out_data, i, &bytes_written, 1000);
+       kfree(out_data);
+       if (retval) {
+-              dev_err(&usb_dev->dev, "%s: agilent_82357a_send_bulk_msg returned %i, bytes_written=%i, i=%i\n",
+-                      __func__, retval, bytes_written, i);
++              dev_err(&usb_dev->dev, "send_bulk_msg returned %i, bytes_written=%i, i=%i\n",
++                      retval, bytes_written, i);
+               mutex_unlock(&a_priv->bulk_transfer_lock);
+               return retval;
+       }
+@@ -265,20 +263,19 @@ static int agilent_82357a_write_registers(struct agilent_82357a_priv *a_priv,
+       mutex_unlock(&a_priv->bulk_transfer_lock);
+       if (retval) {
+-              dev_err(&usb_dev->dev, "%s: agilent_82357a_receive_bulk_msg returned %i, bytes_read=%i\n",
+-                      __func__, retval, bytes_read);
++              dev_err(&usb_dev->dev, "receive_bulk_msg returned %i, bytes_read=%i\n",
++                      retval, bytes_read);
+               agilent_82357a_dump_raw_block(in_data, bytes_read);
+               kfree(in_data);
+               return -EIO;
+       }
+       if (in_data[0] != (0xff & ~DATA_PIPE_CMD_WR_REGS)) {
+-              dev_err(&usb_dev->dev, "%s: error, bulk command=0x%x != ~DATA_PIPE_CMD_WR_REGS\n",
+-                      __func__, in_data[0]);
++              dev_err(&usb_dev->dev, "bulk command=0x%x != ~DATA_PIPE_CMD_WR_REGS\n", in_data[0]);
+               return -EIO;
+       }
+       if (in_data[1]) {
+-              dev_err(&usb_dev->dev, "%s: nonzero error code 0x%x in DATA_PIPE_CMD_WR_REGS response\n",
+-                      __func__, in_data[1]);
++              dev_err(&usb_dev->dev, "nonzero error code 0x%x in DATA_PIPE_CMD_WR_REGS response\n",
++                      in_data[1]);
+               return -EIO;
+       }
+       kfree(in_data);
+@@ -299,9 +296,10 @@ static int agilent_82357a_read_registers(struct agilent_82357a_priv *a_priv,
+       static const int header_length = 2;
+       static const int max_reads = 62;
+-      if (num_reads > max_reads)
+-              dev_err(&usb_dev->dev, "%s: bug! num_reads=%i too large\n", __func__, num_reads);
+-
++      if (num_reads > max_reads) {
++              dev_err(&usb_dev->dev, "bug! num_reads=%i too large\n", num_reads);
++              return -EIO;
++      }
+       out_data_length = num_reads + header_length;
+       out_data = kmalloc(out_data_length, GFP_KERNEL);
+       if (!out_data)
+@@ -311,8 +309,7 @@ static int agilent_82357a_read_registers(struct agilent_82357a_priv *a_priv,
+       out_data[i++] = num_reads;
+       for (j = 0; j < num_reads; j++)
+               out_data[i++] = reads[j].address;
+-      if (i > out_data_length)
+-              dev_err(&usb_dev->dev, "%s: bug! buffer overrun\n", __func__);
++
+       if (blocking) {
+               retval = mutex_lock_interruptible(&a_priv->bulk_transfer_lock);
+               if (retval) {
+@@ -329,8 +326,8 @@ static int agilent_82357a_read_registers(struct agilent_82357a_priv *a_priv,
+       retval = agilent_82357a_send_bulk_msg(a_priv, out_data, i, &bytes_written, 1000);
+       kfree(out_data);
+       if (retval) {
+-              dev_err(&usb_dev->dev, "%s: agilent_82357a_send_bulk_msg returned %i, bytes_written=%i, i=%i\n",
+-                      __func__, retval, bytes_written, i);
++              dev_err(&usb_dev->dev, "send_bulk_msg returned %i, bytes_written=%i, i=%i\n",
++                      retval, bytes_written, i);
+               mutex_unlock(&a_priv->bulk_transfer_lock);
+               return retval;
+       }
+@@ -345,21 +342,20 @@ static int agilent_82357a_read_registers(struct agilent_82357a_priv *a_priv,
+       mutex_unlock(&a_priv->bulk_transfer_lock);
+       if (retval) {
+-              dev_err(&usb_dev->dev, "%s: agilent_82357a_receive_bulk_msg returned %i, bytes_read=%i\n",
+-                      __func__, retval, bytes_read);
++              dev_err(&usb_dev->dev, "receive_bulk_msg returned %i, bytes_read=%i\n",
++                      retval, bytes_read);
+               agilent_82357a_dump_raw_block(in_data, bytes_read);
+               kfree(in_data);
+               return -EIO;
+       }
+       i = 0;
+       if (in_data[i++] != (0xff & ~DATA_PIPE_CMD_RD_REGS)) {
+-              dev_err(&usb_dev->dev, "%s: error, bulk command=0x%x != ~DATA_PIPE_CMD_RD_REGS\n",
+-                      __func__, in_data[0]);
++              dev_err(&usb_dev->dev, "bulk command=0x%x != ~DATA_PIPE_CMD_RD_REGS\n", in_data[0]);
+               return -EIO;
+       }
+       if (in_data[i++]) {
+-              dev_err(&usb_dev->dev, "%s: nonzero error code 0x%x in DATA_PIPE_CMD_RD_REGS response\n",
+-                      __func__, in_data[1]);
++              dev_err(&usb_dev->dev, "nonzero error code 0x%x in DATA_PIPE_CMD_RD_REGS response\n",
++                      in_data[1]);
+               return -EIO;
+       }
+       for (j = 0; j < num_reads; j++)
+@@ -390,14 +386,13 @@ static int agilent_82357a_abort(struct agilent_82357a_priv *a_priv, int flush)
+                                                                   wIndex, status_data,
+                                                                   status_data_len, 100);
+       if (receive_control_retval < 0) {
+-              dev_err(&usb_dev->dev, "%s: agilent_82357a_receive_control_msg() returned %i\n",
+-                      __func__, receive_control_retval);
++              dev_err(&usb_dev->dev, "82357a_receive_control_msg() returned %i\n",
++                      receive_control_retval);
+               retval = -EIO;
+               goto cleanup;
+       }
+       if (status_data[0] != (~XFER_ABORT & 0xff)) {
+-              dev_err(&usb_dev->dev, "%s: error, major code=0x%x != ~XFER_ABORT\n",
+-                      __func__, status_data[0]);
++              dev_err(&usb_dev->dev, "major code=0x%x != ~XFER_ABORT\n", status_data[0]);
+               retval = -EIO;
+               goto cleanup;
+       }
+@@ -413,8 +408,7 @@ static int agilent_82357a_abort(struct agilent_82357a_priv *a_priv, int flush)
+               fallthrough;
+       case UGP_ERR_FLUSHING_ALREADY:
+       default:
+-              dev_err(&usb_dev->dev, "%s: abort returned error code=0x%x\n",
+-                      __func__, status_data[1]);
++              dev_err(&usb_dev->dev, "abort returned error code=0x%x\n", status_data[1]);
+               retval = -EIO;
+               break;
+       }
+@@ -469,8 +463,8 @@ static int agilent_82357a_read(gpib_board_t *board, uint8_t *buffer, size_t leng
+       retval = agilent_82357a_send_bulk_msg(a_priv, out_data, i, &bytes_written, msec_timeout);
+       kfree(out_data);
+       if (retval || bytes_written != i) {
+-              dev_err(&usb_dev->dev, "%s: agilent_82357a_send_bulk_msg returned %i, bytes_written=%i, i=%i\n",
+-                      __func__, retval, bytes_written, i);
++              dev_err(&usb_dev->dev, "send_bulk_msg returned %i, bytes_written=%i, i=%i\n",
++                      retval, bytes_written, i);
+               mutex_unlock(&a_priv->bulk_transfer_lock);
+               if (retval < 0)
+                       return retval;
+@@ -501,19 +495,19 @@ static int agilent_82357a_read(gpib_board_t *board, uint8_t *buffer, size_t leng
+                                                                    &extra_bytes_read, 100);
+               bytes_read += extra_bytes_read;
+               if (extra_bytes_retval) {
+-                      dev_err(&usb_dev->dev, "%s: extra_bytes_retval=%i, bytes_read=%i\n",
+-                              __func__, extra_bytes_retval, bytes_read);
++                      dev_err(&usb_dev->dev, "extra_bytes_retval=%i, bytes_read=%i\n",
++                              extra_bytes_retval, bytes_read);
+                       agilent_82357a_abort(a_priv, 0);
+               }
+       } else if (retval) {
+-              dev_err(&usb_dev->dev, "%s: agilent_82357a_receive_bulk_msg returned %i, bytes_read=%i\n",
+-                      __func__, retval, bytes_read);
++              dev_err(&usb_dev->dev, "receive_bulk_msg returned %i, bytes_read=%i\n",
++                      retval, bytes_read);
+               agilent_82357a_abort(a_priv, 0);
+       }
+       mutex_unlock(&a_priv->bulk_transfer_lock);
+       if (bytes_read > length + 1) {
+               bytes_read = length + 1;
+-              pr_warn("%s: bytes_read > length? truncating", __func__);
++              dev_warn(&usb_dev->dev, "bytes_read > length? truncating");
+       }
+       if (bytes_read >= 1) {
+@@ -584,8 +578,8 @@ static ssize_t agilent_82357a_generic_write(gpib_board_t *board, uint8_t *buffer
+       kfree(out_data);
+       if (retval || raw_bytes_written != i) {
+               agilent_82357a_abort(a_priv, 0);
+-              dev_err(&usb_dev->dev, "%s: agilent_82357a_send_bulk_msg returned %i, raw_bytes_written=%i, i=%i\n",
+-                      __func__, retval, raw_bytes_written, i);
++              dev_err(&usb_dev->dev, "send_bulk_msg returned %i, raw_bytes_written=%i, i=%i\n",
++                      retval, raw_bytes_written, i);
+               mutex_unlock(&a_priv->bulk_transfer_lock);
+               if (retval < 0)
+                       return retval;
+@@ -597,7 +591,7 @@ static ssize_t agilent_82357a_generic_write(gpib_board_t *board, uint8_t *buffer
+                                                  &a_priv->interrupt_flags) ||
+                                         test_bit(TIMO_NUM, &board->status));
+       if (retval) {
+-              dev_err(&usb_dev->dev, "%s: wait write complete interrupted\n", __func__);
++              dev_dbg(&usb_dev->dev, "wait write complete interrupted\n");
+               agilent_82357a_abort(a_priv, 0);
+               mutex_unlock(&a_priv->bulk_transfer_lock);
+               return -ERESTARTSYS;
+@@ -614,8 +608,7 @@ static ssize_t agilent_82357a_generic_write(gpib_board_t *board, uint8_t *buffer
+               read_reg.address = BSR;
+               retval = agilent_82357a_read_registers(a_priv, &read_reg, 1, 1);
+               if (retval) {
+-                      dev_err(&usb_dev->dev, "%s: agilent_82357a_read_registers() returned error\n",
+-                              __func__);
++                      dev_err(&usb_dev->dev, "read_registers() returned error\n");
+                       return -ETIMEDOUT;
+               }
+@@ -632,8 +625,7 @@ static ssize_t agilent_82357a_generic_write(gpib_board_t *board, uint8_t *buffer
+                       read_reg.address = ADSR;
+                       retval = agilent_82357a_read_registers(a_priv, &read_reg, 1, 1);
+                       if (retval) {
+-                              dev_err(&usb_dev->dev, "%s: agilent_82357a_read_registers() returned error\n",
+-                                      __func__);
++                              dev_err(&usb_dev->dev, "read_registers() returned error\n");
+                               return -ETIMEDOUT;
+                       }
+                       adsr = read_reg.value;
+@@ -659,8 +651,7 @@ static ssize_t agilent_82357a_generic_write(gpib_board_t *board, uint8_t *buffer
+                                                   100);
+       mutex_unlock(&a_priv->bulk_transfer_lock);
+       if (retval < 0) {
+-              dev_err(&usb_dev->dev, "%s: agilent_82357a_receive_control_msg() returned %i\n",
+-                      __func__, retval);
++              dev_err(&usb_dev->dev, "receive_control_msg() returned %i\n", retval);
+               kfree(status_data);
+               return -EIO;
+       }
+@@ -699,8 +690,7 @@ int agilent_82357a_take_control_internal(gpib_board_t *board, int synchronous)
+               write.value = AUX_TCA;
+       retval = agilent_82357a_write_registers(a_priv, &write, 1);
+       if (retval)
+-              dev_err(&usb_dev->dev, "%s: agilent_82357a_write_registers() returned error\n",
+-                      __func__);
++              dev_err(&usb_dev->dev, "write_registers() returned error\n");
+       return retval;
+ }
+@@ -741,8 +731,7 @@ static int agilent_82357a_go_to_standby(gpib_board_t *board)
+       write.value = AUX_GTS;
+       retval = agilent_82357a_write_registers(a_priv, &write, 1);
+       if (retval)
+-              dev_err(&usb_dev->dev, "%s: agilent_82357a_write_registers() returned error\n",
+-                      __func__);
++              dev_err(&usb_dev->dev, "write_registers() returned error\n");
+       return 0;
+ }
+@@ -771,8 +760,7 @@ static void agilent_82357a_request_system_control(gpib_board_t *board, int reque
+       ++i;
+       retval = agilent_82357a_write_registers(a_priv, writes, i);
+       if (retval)
+-              dev_err(&usb_dev->dev, "%s: agilent_82357a_write_registers() returned error\n",
+-                      __func__);
++              dev_err(&usb_dev->dev, "write_registers() returned error\n");
+       return;// retval;
+ }
+@@ -791,8 +779,7 @@ static void agilent_82357a_interface_clear(gpib_board_t *board, int assert)
+       }
+       retval = agilent_82357a_write_registers(a_priv, &write, 1);
+       if (retval)
+-              dev_err(&usb_dev->dev, "%s: agilent_82357a_write_registers() returned error\n",
+-                      __func__);
++              dev_err(&usb_dev->dev, "write_registers() returned error\n");
+ }
+ static void agilent_82357a_remote_enable(gpib_board_t *board, int enable)
+@@ -808,8 +795,7 @@ static void agilent_82357a_remote_enable(gpib_board_t *board, int enable)
+               write.value |= AUX_CS;
+       retval = agilent_82357a_write_registers(a_priv, &write, 1);
+       if (retval)
+-              dev_err(&usb_dev->dev, "%s: agilent_82357a_write_registers() returned error\n",
+-                      __func__);
++              dev_err(&usb_dev->dev, "write_registers() returned error\n");
+       a_priv->ren_state = enable;
+       return;// 0;
+ }
+@@ -818,10 +804,9 @@ static int agilent_82357a_enable_eos(gpib_board_t *board, uint8_t eos_byte, int
+ {
+       struct agilent_82357a_priv *a_priv = board->private_data;
+-      if (compare_8_bits == 0) {
+-              pr_warn("%s: hardware only supports 8-bit EOS compare", __func__);
++      if (compare_8_bits == 0)
+               return -EOPNOTSUPP;
+-      }
++
+       a_priv->eos_char = eos_byte;
+       a_priv->eos_mode = REOS | BIN;
+       return 0;
+@@ -850,8 +835,7 @@ static unsigned int agilent_82357a_update_status(gpib_board_t *board, unsigned i
+       retval = agilent_82357a_read_registers(a_priv, &address_status, 1, 0);
+       if (retval) {
+               if (retval != -EAGAIN)
+-                      dev_err(&usb_dev->dev, "%s: agilent_82357a_read_registers() returned error\n",
+-                              __func__);
++                      dev_err(&usb_dev->dev, "read_registers() returned error\n");
+               return board->status;
+       }
+       // check for remote/local
+@@ -883,8 +867,7 @@ static unsigned int agilent_82357a_update_status(gpib_board_t *board, unsigned i
+       retval = agilent_82357a_read_registers(a_priv, &bus_status, 1, 0);
+       if (retval) {
+               if (retval != -EAGAIN)
+-                      dev_err(&usb_dev->dev, "%s: agilent_82357a_read_registers() returned error\n",
+-                              __func__);
++                      dev_err(&usb_dev->dev, "read_registers() returned error\n");
+               return board->status;
+       }
+       if (bus_status.value & BSR_SRQ_BIT)
+@@ -907,8 +890,7 @@ static int agilent_82357a_primary_address(gpib_board_t *board, unsigned int addr
+       write.value = address & ADDRESS_MASK;
+       retval = agilent_82357a_write_registers(a_priv, &write, 1);
+       if (retval) {
+-              dev_err(&usb_dev->dev, "%s: agilent_82357a_write_registers() returned error\n",
+-                      __func__);
++              dev_err(&usb_dev->dev, "write_registers() returned error\n");
+               return retval;
+       }
+       return retval;
+@@ -917,8 +899,8 @@ static int agilent_82357a_primary_address(gpib_board_t *board, unsigned int addr
+ static int agilent_82357a_secondary_address(gpib_board_t *board, unsigned int address, int enable)
+ {
+       if (enable)
+-              pr_warn("%s: warning: assigning a secondary address not supported\n", __func__);
+-      return  -EOPNOTSUPP;
++              return  -EOPNOTSUPP;
++      return 0;
+ }
+ static int agilent_82357a_parallel_poll(gpib_board_t *board, uint8_t *result)
+@@ -936,16 +918,14 @@ static int agilent_82357a_parallel_poll(gpib_board_t *board, uint8_t *result)
+       writes[1].value = a_priv->hw_control_bits & ~NOT_PARALLEL_POLL;
+       retval = agilent_82357a_write_registers(a_priv, writes, 2);
+       if (retval) {
+-              dev_err(&usb_dev->dev, "%s: agilent_82357a_write_registers() returned error\n",
+-                      __func__);
++              dev_err(&usb_dev->dev, "write_registers() returned error\n");
+               return retval;
+       }
+       udelay(2);      //silly, since usb write will take way longer
+       read.address = CPTR;
+       retval = agilent_82357a_read_registers(a_priv, &read, 1, 1);
+       if (retval) {
+-              dev_err(&usb_dev->dev, "%s: agilent_82357a_read_registers() returned error\n",
+-                      __func__);
++              dev_err(&usb_dev->dev, "read_registers() returned error\n");
+               return retval;
+       }
+       *result = read.value;
+@@ -956,8 +936,7 @@ static int agilent_82357a_parallel_poll(gpib_board_t *board, uint8_t *result)
+       writes[1].value = AUX_RPP;
+       retval = agilent_82357a_write_registers(a_priv, writes, 2);
+       if (retval) {
+-              dev_err(&usb_dev->dev, "%s: agilent_82357a_write_registers() returned error\n",
+-                      __func__);
++              dev_err(&usb_dev->dev, "write_registers() returned error\n");
+               return retval;
+       }
+       return 0;
+@@ -1005,8 +984,7 @@ static int agilent_82357a_line_status(const gpib_board_t *board)
+       retval = agilent_82357a_read_registers(a_priv, &bus_status, 1, 0);
+       if (retval) {
+               if (retval != -EAGAIN)
+-                      dev_err(&usb_dev->dev, "%s: agilent_82357a_read_registers() returned error\n",
+-                              __func__);
++                      dev_err(&usb_dev->dev, "read_registers() returned error\n");
+               return retval;
+       }
+       if (bus_status.value & BSR_REN_BIT)
+@@ -1055,8 +1033,7 @@ static unsigned int agilent_82357a_t1_delay(gpib_board_t *board, unsigned int na
+       write.value = nanosec_to_fast_talker_bits(&nanosec);
+       retval = agilent_82357a_write_registers(a_priv, &write, 1);
+       if (retval)
+-              dev_err(&usb_dev->dev, "%s: agilent_82357a_write_registers() returned error\n",
+-                      __func__);
++              dev_err(&usb_dev->dev, "write_registers() returned error\n");
+       return nanosec;
+ }
+@@ -1081,7 +1058,7 @@ static void agilent_82357a_interrupt_complete(struct urb *urb)
+       default: /* other error, resubmit */
+               retval = usb_submit_urb(a_priv->interrupt_urb, GFP_ATOMIC);
+               if (retval)
+-                      dev_err(&usb_dev->dev, "%s: failed to resubmit interrupt urb\n", __func__);
++                      dev_err(&usb_dev->dev, "failed to resubmit interrupt urb\n");
+               return;
+       }
+@@ -1097,7 +1074,7 @@ static void agilent_82357a_interrupt_complete(struct urb *urb)
+       retval = usb_submit_urb(a_priv->interrupt_urb, GFP_ATOMIC);
+       if (retval)
+-              dev_err(&usb_dev->dev, "%s: failed to resubmit interrupt urb\n", __func__);
++              dev_err(&usb_dev->dev, "failed to resubmit interrupt urb\n");
+ }
+ static int agilent_82357a_setup_urbs(gpib_board_t *board)
+@@ -1133,8 +1110,7 @@ static int agilent_82357a_setup_urbs(gpib_board_t *board)
+       if (retval) {
+               usb_free_urb(a_priv->interrupt_urb);
+               a_priv->interrupt_urb = NULL;
+-              dev_err(&usb_dev->dev, "%s: failed to submit first interrupt urb, retval=%i\n",
+-                      __func__, retval);
++              dev_err(&usb_dev->dev, "failed to submit first interrupt urb, retval=%i\n", retval);
+               goto setup_exit;
+       }
+       mutex_unlock(&a_priv->interrupt_alloc_lock);
+@@ -1184,108 +1160,78 @@ static void agilent_82357a_free_private(gpib_board_t *board)
+ {
+       kfree(board->private_data);
+       board->private_data = NULL;
+-
+ }
++#define INIT_NUM_REG_WRITES 18
+ static int agilent_82357a_init(gpib_board_t *board)
+ {
+       struct agilent_82357a_priv *a_priv = board->private_data;
+       struct usb_device *usb_dev = interface_to_usbdev(a_priv->bus_interface);
+       struct agilent_82357a_register_pairlet hw_control;
+-      struct agilent_82357a_register_pairlet writes[0x20];
++      struct agilent_82357a_register_pairlet writes[INIT_NUM_REG_WRITES];
+       int retval;
+-      int i;
+       unsigned int nanosec;
+-      i = 0;
+-      writes[i].address = LED_CONTROL;
+-      writes[i].value = FAIL_LED_ON;
+-      ++i;
+-      writes[i].address = RESET_TO_POWERUP;
+-      writes[i].value = RESET_SPACEBALL;
+-      ++i;
+-      retval = agilent_82357a_write_registers(a_priv, writes, i);
++      writes[0].address = LED_CONTROL;
++      writes[0].value = FAIL_LED_ON;
++      writes[1].address = RESET_TO_POWERUP;
++      writes[1].value = RESET_SPACEBALL;
++      retval = agilent_82357a_write_registers(a_priv, writes, 2);
+       if (retval) {
+-              dev_err(&usb_dev->dev, "%s: agilent_82357a_write_registers() returned error\n",
+-                      __func__);
++              dev_err(&usb_dev->dev, "write_registers() returned error\n");
+               return -EIO;
+       }
+       set_current_state(TASK_INTERRUPTIBLE);
+       if (schedule_timeout(usec_to_jiffies(2000)))
+               return -ERESTARTSYS;
+-      i = 0;
+-      writes[i].address = AUXCR;
+-      writes[i].value = AUX_NBAF;
+-      ++i;
+-      writes[i].address = AUXCR;
+-      writes[i].value = AUX_HLDE;
+-      ++i;
+-      writes[i].address = AUXCR;
+-      writes[i].value = AUX_TON;
+-      ++i;
+-      writes[i].address = AUXCR;
+-      writes[i].value = AUX_LON;
+-      ++i;
+-      writes[i].address = AUXCR;
+-      writes[i].value = AUX_RSV2;
+-      ++i;
+-      writes[i].address = AUXCR;
+-      writes[i].value = AUX_INVAL;
+-      ++i;
+-      writes[i].address = AUXCR;
+-      writes[i].value = AUX_RPP;
+-      ++i;
+-      writes[i].address = AUXCR;
+-      writes[i].value = AUX_STDL;
+-      ++i;
+-      writes[i].address = AUXCR;
+-      writes[i].value = AUX_VSTDL;
+-      ++i;
+-      writes[i].address = FAST_TALKER_T1;
++      writes[0].address = AUXCR;
++      writes[0].value = AUX_NBAF;
++      writes[1].address = AUXCR;
++      writes[1].value = AUX_HLDE;
++      writes[2].address = AUXCR;
++      writes[2].value = AUX_TON;
++      writes[3].address = AUXCR;
++      writes[3].value = AUX_LON;
++      writes[4].address = AUXCR;
++      writes[4].value = AUX_RSV2;
++      writes[5].address = AUXCR;
++      writes[5].value = AUX_INVAL;
++      writes[6].address = AUXCR;
++      writes[6].value = AUX_RPP;
++      writes[7].address = AUXCR;
++      writes[7].value = AUX_STDL;
++      writes[8].address = AUXCR;
++      writes[8].value = AUX_VSTDL;
++      writes[9].address = FAST_TALKER_T1;
+       nanosec = board->t1_nano_sec;
+-      writes[i].value = nanosec_to_fast_talker_bits(&nanosec);
++      writes[9].value = nanosec_to_fast_talker_bits(&nanosec);
+       board->t1_nano_sec = nanosec;
+-      ++i;
+-      writes[i].address = ADR;
+-      writes[i].value = board->pad & ADDRESS_MASK;
+-      ++i;
+-      writes[i].address = PPR;
+-      writes[i].value = 0;
+-      ++i;
+-      writes[i].address = SPMR;
+-      writes[i].value = 0;
+-      ++i;
+-      writes[i].address = PROTOCOL_CONTROL;
+-      writes[i].value = WRITE_COMPLETE_INTERRUPT_EN;
+-      ++i;
+-      writes[i].address = IMR0;
+-      writes[i].value = HR_BOIE | HR_BIIE;
+-      ++i;
+-      writes[i].address = IMR1;
+-      writes[i].value = HR_SRQIE;
+-      ++i;
++      writes[10].address = ADR;
++      writes[10].value = board->pad & ADDRESS_MASK;
++      writes[11].address = PPR;
++      writes[11].value = 0;
++      writes[12].address = SPMR;
++      writes[12].value = 0;
++      writes[13].address = PROTOCOL_CONTROL;
++      writes[13].value = WRITE_COMPLETE_INTERRUPT_EN;
++      writes[14].address = IMR0;
++      writes[14].value = HR_BOIE | HR_BIIE;
++      writes[15].address = IMR1;
++      writes[15].value = HR_SRQIE;
+       // turn off reset state
+-      writes[i].address = AUXCR;
+-      writes[i].value = AUX_CHIP_RESET;
+-      ++i;
+-      writes[i].address = LED_CONTROL;
+-      writes[i].value = FIRMWARE_LED_CONTROL;
+-      ++i;
+-      if (i > ARRAY_SIZE(writes)) {
+-              dev_err(&usb_dev->dev, "%s: bug! writes[] overflow\n", __func__);
+-              return -EFAULT;
+-      }
+-      retval = agilent_82357a_write_registers(a_priv, writes, i);
++      writes[16].address = AUXCR;
++      writes[16].value = AUX_CHIP_RESET;
++      writes[17].address = LED_CONTROL;
++      writes[17].value = FIRMWARE_LED_CONTROL;
++      retval = agilent_82357a_write_registers(a_priv, writes, INIT_NUM_REG_WRITES);
+       if (retval) {
+-              dev_err(&usb_dev->dev, "%s: agilent_82357a_write_registers() returned error\n",
+-                      __func__);
++              dev_err(&usb_dev->dev, "write_registers() returned error\n");
+               return -EIO;
+       }
+       hw_control.address = HW_CONTROL;
+       retval = agilent_82357a_read_registers(a_priv, &hw_control, 1, 1);
+       if (retval) {
+-              dev_err(&usb_dev->dev, "%s: agilent_82357a_read_registers() returned error\n",
+-                      __func__);
++              dev_err(&usb_dev->dev, "read_registers() returned error\n");
+               return -EIO;
+       }
+       a_priv->hw_control_bits = (hw_control.value & ~0x7) | NOT_TI_RESET | NOT_PARALLEL_POLL;
+@@ -1336,7 +1282,7 @@ static int agilent_82357a_attach(gpib_board_t *board, const gpib_board_config_t
+       }
+       if (i == MAX_NUM_82357A_INTERFACES) {
+               dev_err(board->gpib_dev,
+-                      "No Agilent 82357 gpib adapters found, have you loaded its firmware?\n");
++                      "No supported adapters found, have you loaded its firmware?\n");
+               retval = -ENODEV;
+               goto attach_fail;
+       }
+@@ -1372,8 +1318,7 @@ static int agilent_82357a_attach(gpib_board_t *board, const gpib_board_config_t
+               goto attach_fail;
+       }
+-      dev_info(&usb_dev->dev,
+-               "bus %d dev num %d attached to gpib minor %d, agilent usb interface %i\n",
++      dev_info(&usb_dev->dev, "bus %d dev num %d attached to gpib%d, interface %i\n",
+                usb_dev->bus->busnum, usb_dev->devnum, board->minor, i);
+       mutex_unlock(&agilent_82357a_hotplug_lock);
+       return retval;
+@@ -1390,37 +1335,24 @@ static int agilent_82357a_go_idle(gpib_board_t *board)
+       struct usb_device *usb_dev = interface_to_usbdev(a_priv->bus_interface);
+       struct agilent_82357a_register_pairlet writes[0x20];
+       int retval;
+-      int i;
+-      i = 0;
+       // turn on tms9914 reset state
+-      writes[i].address = AUXCR;
+-      writes[i].value = AUX_CS | AUX_CHIP_RESET;
+-      ++i;
++      writes[0].address = AUXCR;
++      writes[0].value = AUX_CS | AUX_CHIP_RESET;
+       a_priv->hw_control_bits &= ~NOT_TI_RESET;
+-      writes[i].address = HW_CONTROL;
+-      writes[i].value = a_priv->hw_control_bits;
+-      ++i;
+-      writes[i].address = PROTOCOL_CONTROL;
+-      writes[i].value = 0;
+-      ++i;
+-      writes[i].address = IMR0;
+-      writes[i].value = 0;
+-      ++i;
+-      writes[i].address = IMR1;
+-      writes[i].value = 0;
+-      ++i;
+-      writes[i].address = LED_CONTROL;
+-      writes[i].value = 0;
+-      ++i;
+-      if (i > ARRAY_SIZE(writes)) {
+-              dev_err(&usb_dev->dev, "%s: bug! writes[] overflow\n", __func__);
+-              return -EFAULT;
+-      }
+-      retval = agilent_82357a_write_registers(a_priv, writes, i);
++      writes[1].address = HW_CONTROL;
++      writes[1].value = a_priv->hw_control_bits;
++      writes[2].address = PROTOCOL_CONTROL;
++      writes[2].value = 0;
++      writes[3].address = IMR0;
++      writes[3].value = 0;
++      writes[4].address = IMR1;
++      writes[4].value = 0;
++      writes[5].address = LED_CONTROL;
++      writes[5].value = 0;
++      retval = agilent_82357a_write_registers(a_priv, writes, 6);
+       if (retval) {
+-              dev_err(&usb_dev->dev, "%s: agilent_82357a_write_registers() returned error\n",
+-                      __func__);
++              dev_err(&usb_dev->dev, "write_registers() returned error\n");
+               return -EIO;
+       }
+       return 0;
+@@ -1445,7 +1377,6 @@ static void agilent_82357a_detach(gpib_board_t *board)
+               agilent_82357a_release_urbs(a_priv);
+               agilent_82357a_free_private(board);
+       }
+-      dev_info(board->gpib_dev, "%s: detached\n", __func__);
+       mutex_unlock(&agilent_82357a_hotplug_lock);
+ }
+@@ -1510,8 +1441,7 @@ static int agilent_82357a_driver_probe(struct usb_interface *interface,
+       if (i == MAX_NUM_82357A_INTERFACES) {
+               usb_put_dev(usb_dev);
+               mutex_unlock(&agilent_82357a_hotplug_lock);
+-              dev_err(&usb_dev->dev, "%s: out of space in agilent_82357a_driver_interfaces[]\n",
+-                      __func__);
++              dev_err(&usb_dev->dev, "out of space in agilent_82357a_driver_interfaces[]\n");
+               return -1;
+       }
+       path = kmalloc(path_length, GFP_KERNEL);
+@@ -1552,13 +1482,12 @@ static void agilent_82357a_driver_disconnect(struct usb_interface *interface)
+                                       mutex_unlock(&a_priv->control_alloc_lock);
+                               }
+                       }
+-                      dev_dbg(&usb_dev->dev, "nulled agilent_82357a_driver_interfaces[%i]\n", i);
+                       agilent_82357a_driver_interfaces[i] = NULL;
+                       break;
+               }
+       }
+       if (i == MAX_NUM_82357A_INTERFACES)
+-              dev_err(&usb_dev->dev, "unable to find interface in agilent_82357a_driver_interfaces[]? bug?\n");
++              dev_err(&usb_dev->dev, "unable to find interface - bug?\n");
+       usb_put_dev(usb_dev);
+       mutex_unlock(&agilent_82357a_hotplug_lock);
+@@ -1583,18 +1512,18 @@ static int agilent_82357a_driver_suspend(struct usb_interface *interface, pm_mes
+                                       agilent_82357a_abort(a_priv, 0);
+                                       retval = agilent_82357a_go_idle(board);
+                                       if (retval) {
+-                                              dev_err(&usb_dev->dev, "%s: failed to go idle, retval=%i\n",
+-                                                      __func__, retval);
++                                              dev_err(&usb_dev->dev, "failed to go idle, retval=%i\n",
++                                                      retval);
+                                               mutex_unlock(&agilent_82357a_hotplug_lock);
+                                               return retval;
+                                       }
+                                       mutex_lock(&a_priv->interrupt_alloc_lock);
+                                       agilent_82357a_cleanup_urbs(a_priv);
+                                       mutex_unlock(&a_priv->interrupt_alloc_lock);
+-                                      dev_info(&usb_dev->dev,
+-                                               "bus %d dev num %d  gpib minor %d, agilent usb interface %i suspended\n",
+-                                               usb_dev->bus->busnum, usb_dev->devnum,
+-                                               board->minor, i);
++                                      dev_dbg(&usb_dev->dev,
++                                              "bus %d dev num %d gpib %d, interface %i suspended\n",
++                                              usb_dev->bus->busnum, usb_dev->devnum,
++                                              board->minor, i);
+                               }
+                       }
+                       break;
+@@ -1631,8 +1560,8 @@ static int agilent_82357a_driver_resume(struct usb_interface *interface)
+                       mutex_lock(&a_priv->interrupt_alloc_lock);
+                       retval = usb_submit_urb(a_priv->interrupt_urb, GFP_KERNEL);
+                       if (retval) {
+-                              dev_err(&usb_dev->dev, "%s: failed to resubmit interrupt urb, retval=%i\n",
+-                                      __func__, retval);
++                              dev_err(&usb_dev->dev, "failed to resubmit interrupt urb in resume, retval=%i\n",
++                                      retval);
+                               mutex_unlock(&a_priv->interrupt_alloc_lock);
+                               mutex_unlock(&agilent_82357a_hotplug_lock);
+                               return retval;
+@@ -1655,9 +1584,9 @@ static int agilent_82357a_driver_resume(struct usb_interface *interface)
+               // assert/unassert REN
+               agilent_82357a_remote_enable(board, a_priv->ren_state);
+-              dev_info(&usb_dev->dev,
+-                       "bus %d dev num %d  gpib minor %d, agilent usb interface %i resumed\n",
+-                       usb_dev->bus->busnum, usb_dev->devnum, board->minor, i);
++              dev_dbg(&usb_dev->dev,
++                      "bus %d dev num %d gpib%d, interface %i resumed\n",
++                      usb_dev->bus->busnum, usb_dev->devnum, board->minor, i);
+       }
+ resume_exit:
+@@ -1667,7 +1596,7 @@ static int agilent_82357a_driver_resume(struct usb_interface *interface)
+ }
+ static struct usb_driver agilent_82357a_bus_driver = {
+-      .name = "agilent_82357a_gpib",
++      .name = DRV_NAME,
+       .probe = agilent_82357a_driver_probe,
+       .disconnect = agilent_82357a_driver_disconnect,
+       .suspend = agilent_82357a_driver_suspend,
+@@ -1680,19 +1609,18 @@ static int __init agilent_82357a_init_module(void)
+       int i;
+       int ret;
+-      pr_info("agilent_82357a_gpib driver loading");
+       for (i = 0; i < MAX_NUM_82357A_INTERFACES; ++i)
+               agilent_82357a_driver_interfaces[i] = NULL;
+       ret = usb_register(&agilent_82357a_bus_driver);
+       if (ret) {
+-              pr_err("agilent_82357a: usb_register failed: error = %d\n", ret);
++              pr_err("usb_register failed: error = %d\n", ret);
+               return ret;
+       }
+       ret = gpib_register_driver(&agilent_82357a_gpib_interface, THIS_MODULE);
+       if (ret) {
+-              pr_err("agilent_82357a: gpib_register_driver failed: error = %d\n", ret);
++              pr_err("gpib_register_driver failed: error = %d\n", ret);
+               usb_deregister(&agilent_82357a_bus_driver);
+               return ret;
+       }
+@@ -1702,7 +1630,6 @@ static int __init agilent_82357a_init_module(void)
+ static void __exit agilent_82357a_exit_module(void)
+ {
+-      pr_info("agilent_82357a_gpib driver unloading");
+       gpib_unregister_driver(&agilent_82357a_gpib_interface);
+       usb_deregister(&agilent_82357a_bus_driver);
+ }
+-- 
+2.39.5
+
diff --git a/queue-6.13/staging-gpib-agilent_82357a-handle-gpib_register_dri.patch b/queue-6.13/staging-gpib-agilent_82357a-handle-gpib_register_dri.patch
new file mode 100644 (file)
index 0000000..9b2839b
--- /dev/null
@@ -0,0 +1,61 @@
+From 354879add917bf25eee3781a73e607e9d8227204 Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Tue, 31 Dec 2024 00:26:23 +0530
+Subject: staging: gpib: agilent_82357a: Handle gpib_register_driver() errors
+
+From: Nihar Chaithanya <niharchaithanya@gmail.com>
+
+[ Upstream commit 9e43ebc613e2adb9b9e900e11a4099e104b61f2d ]
+
+The usb_register() function can fail and returns an error value which
+is not returned. The function gpib_register_driver() can also fail
+which can result in semi-registered module.
+
+In case gpib_register_driver() fails unregister the previous usb driver
+registering function. Return the error value if gpib_register_driver()
+or usb_register() functions fail. Add pr_err when registering driver
+fails also indicating the error value.
+
+Signed-off-by: Nihar Chaithanya <niharchaithanya@gmail.com>
+Link: https://lore.kernel.org/r/20241230185633.175690-4-niharchaithanya@gmail.com
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Stable-dep-of: 8491e73a5223 ("staging: gpib: Fix Oops after disconnect in agilent usb")
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ .../staging/gpib/agilent_82357a/agilent_82357a.c | 16 ++++++++++++++--
+ 1 file changed, 14 insertions(+), 2 deletions(-)
+
+diff --git a/drivers/staging/gpib/agilent_82357a/agilent_82357a.c b/drivers/staging/gpib/agilent_82357a/agilent_82357a.c
+index bf05fb4a736b3..261fb6d2e9916 100644
+--- a/drivers/staging/gpib/agilent_82357a/agilent_82357a.c
++++ b/drivers/staging/gpib/agilent_82357a/agilent_82357a.c
+@@ -1691,12 +1691,24 @@ static struct usb_driver agilent_82357a_bus_driver = {
+ static int __init agilent_82357a_init_module(void)
+ {
+       int i;
++      int ret;
+       pr_info("agilent_82357a_gpib driver loading");
+       for (i = 0; i < MAX_NUM_82357A_INTERFACES; ++i)
+               agilent_82357a_driver_interfaces[i] = NULL;
+-      usb_register(&agilent_82357a_bus_driver);
+-      gpib_register_driver(&agilent_82357a_gpib_interface, THIS_MODULE);
++
++      ret = usb_register(&agilent_82357a_bus_driver);
++      if (ret) {
++              pr_err("agilent_82357a: usb_register failed: error = %d\n", ret);
++              return ret;
++      }
++
++      ret = gpib_register_driver(&agilent_82357a_gpib_interface, THIS_MODULE);
++      if (ret) {
++              pr_err("agilent_82357a: gpib_register_driver failed: error = %d\n", ret);
++              usb_deregister(&agilent_82357a_bus_driver);
++              return ret;
++      }
+       return 0;
+ }
+-- 
+2.39.5
+
diff --git a/queue-6.13/staging-gpib-fix-null-pointer-dereference-in-detach.patch b/queue-6.13/staging-gpib-fix-null-pointer-dereference-in-detach.patch
new file mode 100644 (file)
index 0000000..8bf657c
--- /dev/null
@@ -0,0 +1,56 @@
+From 9b57e4002c95847b0953027e0cbaa40624fa44c3 Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Sat, 18 Jan 2025 15:50:45 +0100
+Subject: staging: gpib: Fix NULL pointer dereference in detach
+
+From: Dave Penkler <dpenkler@gmail.com>
+
+[ Upstream commit 6a6c153537f093c3bc79ea9633f3954d3450d0ba ]
+
+When the detach function is called after a failed attach
+the usb_dev initialization can cause a NULL pointer
+dereference. This happens when the usb device is not found
+in the attach procedure.
+
+Remove the usb_dev variable and initialization and change the dev
+in the dev_info message from the usb_dev to the gpib_dev.
+
+Fixes: fbae7090f30c ("staging: gpib: Update messaging and usb_device refs in agilent_usb")
+Signed-off-by: Dave Penkler <dpenkler@gmail.com>
+Link: https://lore.kernel.org/r/20250118145046.12181-2-dpenkler@gmail.com
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Stable-dep-of: 8491e73a5223 ("staging: gpib: Fix Oops after disconnect in agilent usb")
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ drivers/staging/gpib/agilent_82357a/agilent_82357a.c | 4 +---
+ 1 file changed, 1 insertion(+), 3 deletions(-)
+
+diff --git a/drivers/staging/gpib/agilent_82357a/agilent_82357a.c b/drivers/staging/gpib/agilent_82357a/agilent_82357a.c
+index 942ab663e4001..d072c63651629 100644
+--- a/drivers/staging/gpib/agilent_82357a/agilent_82357a.c
++++ b/drivers/staging/gpib/agilent_82357a/agilent_82357a.c
+@@ -1442,12 +1442,10 @@ static int agilent_82357a_go_idle(gpib_board_t *board)
+ static void agilent_82357a_detach(gpib_board_t *board)
+ {
+       struct agilent_82357a_priv *a_priv;
+-      struct usb_device *usb_dev;
+       mutex_lock(&agilent_82357a_hotplug_lock);
+       a_priv = board->private_data;
+-      usb_dev = interface_to_usbdev(a_priv->bus_interface);
+       if (a_priv) {
+               if (a_priv->bus_interface) {
+                       agilent_82357a_go_idle(board);
+@@ -1459,7 +1457,7 @@ static void agilent_82357a_detach(gpib_board_t *board)
+               agilent_82357a_cleanup_urbs(a_priv);
+               agilent_82357a_free_private(a_priv);
+       }
+-      dev_info(&usb_dev->dev, "%s: detached\n", __func__);
++      dev_info(board->gpib_dev, "%s: detached\n", __func__);
+       mutex_unlock(&agilent_82357a_hotplug_lock);
+ }
+-- 
+2.39.5
+
diff --git a/queue-6.13/staging-gpib-fix-oops-after-disconnect-in-agilent-us.patch b/queue-6.13/staging-gpib-fix-oops-after-disconnect-in-agilent-us.patch
new file mode 100644 (file)
index 0000000..05b5d0b
--- /dev/null
@@ -0,0 +1,239 @@
+From 6a4fa672819f766e4de988ad41b2e75c7e6b9bcd Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Sat, 22 Feb 2025 21:45:15 +0100
+Subject: staging: gpib: Fix Oops after disconnect in agilent usb
+
+From: Dave Penkler <dpenkler@gmail.com>
+
+[ Upstream commit 8491e73a5223acb0a4b4d78c3f8b96aa9c5e774d ]
+
+If the agilent usb dongle is disconnected subsequent calls to the
+driver cause a NULL dereference Oops as the bus_interface
+is set to NULL on disconnect.
+
+This problem was introduced by setting usb_dev from the bus_interface
+for dev_xxx messages.
+
+Previously bus_interface was checked for NULL only in the functions
+directly calling usb_fill_bulk_urb or usb_control_msg.
+
+Check for valid bus_interface on all interface entry points
+and return -ENODEV if it is NULL.
+
+Fixes: fbae7090f30c ("staging: gpib: Update messaging and usb_device refs in agilent_usb")
+Cc: stable <stable@kernel.org>
+Signed-off-by: Dave Penkler <dpenkler@gmail.com>
+Link: https://lore.kernel.org/r/20250222204515.5104-1-dpenkler@gmail.com
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ .../gpib/agilent_82357a/agilent_82357a.c      | 65 ++++++++++++++++---
+ 1 file changed, 55 insertions(+), 10 deletions(-)
+
+diff --git a/drivers/staging/gpib/agilent_82357a/agilent_82357a.c b/drivers/staging/gpib/agilent_82357a/agilent_82357a.c
+index 7a39056ebc886..438ddc5a84ed3 100644
+--- a/drivers/staging/gpib/agilent_82357a/agilent_82357a.c
++++ b/drivers/staging/gpib/agilent_82357a/agilent_82357a.c
+@@ -427,7 +427,7 @@ static int agilent_82357a_read(gpib_board_t *board, uint8_t *buffer, size_t leng
+ {
+       int retval;
+       struct agilent_82357a_priv *a_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(a_priv->bus_interface);
++      struct usb_device *usb_dev;
+       u8 *out_data, *in_data;
+       int out_data_length, in_data_length;
+       int bytes_written, bytes_read;
+@@ -438,6 +438,10 @@ static int agilent_82357a_read(gpib_board_t *board, uint8_t *buffer, size_t leng
+       *nbytes = 0;
+       *end = 0;
++
++      if (!a_priv->bus_interface)
++              return -ENODEV;
++      usb_dev = interface_to_usbdev(a_priv->bus_interface);
+       out_data_length = 0x9;
+       out_data = kmalloc(out_data_length, GFP_KERNEL);
+       if (!out_data)
+@@ -534,7 +538,7 @@ static ssize_t agilent_82357a_generic_write(gpib_board_t *board, uint8_t *buffer
+ {
+       int retval;
+       struct agilent_82357a_priv *a_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(a_priv->bus_interface);
++      struct usb_device *usb_dev;
+       u8 *out_data = NULL;
+       u8 *status_data = NULL;
+       int out_data_length;
+@@ -545,6 +549,10 @@ static ssize_t agilent_82357a_generic_write(gpib_board_t *board, uint8_t *buffer
+       struct agilent_82357a_register_pairlet read_reg;
+       *bytes_written = 0;
++      if (!a_priv->bus_interface)
++              return -ENODEV;
++
++      usb_dev = interface_to_usbdev(a_priv->bus_interface);
+       out_data_length = length + 0x8;
+       out_data = kmalloc(out_data_length, GFP_KERNEL);
+       if (!out_data)
+@@ -697,9 +705,13 @@ int agilent_82357a_take_control_internal(gpib_board_t *board, int synchronous)
+ static int agilent_82357a_take_control(gpib_board_t *board, int synchronous)
+ {
++      struct agilent_82357a_priv *a_priv = board->private_data;
+       const int timeout = 10;
+       int i;
++      if (!a_priv->bus_interface)
++              return -ENODEV;
++
+ /* It looks like the 9914 does not handle tcs properly.
+  *  See comment above tms9914_take_control_workaround() in
+  *  drivers/gpib/tms9914/tms9914_aux.c
+@@ -723,10 +735,14 @@ static int agilent_82357a_take_control(gpib_board_t *board, int synchronous)
+ static int agilent_82357a_go_to_standby(gpib_board_t *board)
+ {
+       struct agilent_82357a_priv *a_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(a_priv->bus_interface);
++      struct usb_device *usb_dev;
+       struct agilent_82357a_register_pairlet write;
+       int retval;
++      if (!a_priv->bus_interface)
++              return -ENODEV;
++
++      usb_dev = interface_to_usbdev(a_priv->bus_interface);
+       write.address = AUXCR;
+       write.value = AUX_GTS;
+       retval = agilent_82357a_write_registers(a_priv, &write, 1);
+@@ -739,11 +755,15 @@ static int agilent_82357a_go_to_standby(gpib_board_t *board)
+ static void agilent_82357a_request_system_control(gpib_board_t *board, int request_control)
+ {
+       struct agilent_82357a_priv *a_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(a_priv->bus_interface);
++      struct usb_device *usb_dev;
+       struct agilent_82357a_register_pairlet writes[2];
+       int retval;
+       int i = 0;
++      if (!a_priv->bus_interface)
++              return; // -ENODEV;
++
++      usb_dev = interface_to_usbdev(a_priv->bus_interface);
+       /* 82357B needs bit to be set in 9914 AUXCR register */
+       writes[i].address = AUXCR;
+       if (request_control) {
+@@ -767,10 +787,14 @@ static void agilent_82357a_request_system_control(gpib_board_t *board, int reque
+ static void agilent_82357a_interface_clear(gpib_board_t *board, int assert)
+ {
+       struct agilent_82357a_priv *a_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(a_priv->bus_interface);
++      struct usb_device *usb_dev;
+       struct agilent_82357a_register_pairlet write;
+       int retval;
++      if (!a_priv->bus_interface)
++              return; // -ENODEV;
++
++      usb_dev = interface_to_usbdev(a_priv->bus_interface);
+       write.address = AUXCR;
+       write.value = AUX_SIC;
+       if (assert) {
+@@ -785,10 +809,14 @@ static void agilent_82357a_interface_clear(gpib_board_t *board, int assert)
+ static void agilent_82357a_remote_enable(gpib_board_t *board, int enable)
+ {
+       struct agilent_82357a_priv *a_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(a_priv->bus_interface);
++      struct usb_device *usb_dev;
+       struct agilent_82357a_register_pairlet write;
+       int retval;
++      if (!a_priv->bus_interface)
++              return; //-ENODEV;
++
++      usb_dev = interface_to_usbdev(a_priv->bus_interface);
+       write.address = AUXCR;
+       write.value = AUX_SRE;
+       if (enable)
+@@ -804,6 +832,8 @@ static int agilent_82357a_enable_eos(gpib_board_t *board, uint8_t eos_byte, int
+ {
+       struct agilent_82357a_priv *a_priv = board->private_data;
++      if (!a_priv->bus_interface)
++              return -ENODEV;
+       if (compare_8_bits == 0)
+               return -EOPNOTSUPP;
+@@ -822,10 +852,13 @@ static void agilent_82357a_disable_eos(gpib_board_t *board)
+ static unsigned int agilent_82357a_update_status(gpib_board_t *board, unsigned int clear_mask)
+ {
+       struct agilent_82357a_priv *a_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(a_priv->bus_interface);
++      struct usb_device *usb_dev;
+       struct agilent_82357a_register_pairlet address_status, bus_status;
+       int retval;
++      if (!a_priv->bus_interface)
++              return -ENODEV;
++      usb_dev = interface_to_usbdev(a_priv->bus_interface);
+       board->status &= ~clear_mask;
+       if (a_priv->is_cic)
+               set_bit(CIC_NUM, &board->status);
+@@ -885,6 +918,9 @@ static int agilent_82357a_primary_address(gpib_board_t *board, unsigned int addr
+       struct agilent_82357a_register_pairlet write;
+       int retval;
++      if (!a_priv->bus_interface)
++              return -ENODEV;
++      usb_dev = interface_to_usbdev(a_priv->bus_interface);
+       // put primary address in address0
+       write.address = ADR;
+       write.value = address & ADDRESS_MASK;
+@@ -906,11 +942,14 @@ static int agilent_82357a_secondary_address(gpib_board_t *board, unsigned int ad
+ static int agilent_82357a_parallel_poll(gpib_board_t *board, uint8_t *result)
+ {
+       struct agilent_82357a_priv *a_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(a_priv->bus_interface);
++      struct usb_device *usb_dev;
+       struct agilent_82357a_register_pairlet writes[2];
+       struct agilent_82357a_register_pairlet read;
+       int retval;
++      if (!a_priv->bus_interface)
++              return -ENODEV;
++      usb_dev = interface_to_usbdev(a_priv->bus_interface);
+       // execute parallel poll
+       writes[0].address = AUXCR;
+       writes[0].value = AUX_CS | AUX_RPP;
+@@ -975,11 +1014,14 @@ static void agilent_82357a_return_to_local(gpib_board_t *board)
+ static int agilent_82357a_line_status(const gpib_board_t *board)
+ {
+       struct agilent_82357a_priv *a_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(a_priv->bus_interface);
++      struct usb_device *usb_dev;
+       struct agilent_82357a_register_pairlet bus_status;
+       int retval;
+       int status = ValidALL;
++      if (!a_priv->bus_interface)
++              return -ENODEV;
++      usb_dev = interface_to_usbdev(a_priv->bus_interface);
+       bus_status.address = BSR;
+       retval = agilent_82357a_read_registers(a_priv, &bus_status, 1, 0);
+       if (retval) {
+@@ -1025,10 +1067,13 @@ static unsigned short nanosec_to_fast_talker_bits(unsigned int *nanosec)
+ static unsigned int agilent_82357a_t1_delay(gpib_board_t *board, unsigned int nanosec)
+ {
+       struct agilent_82357a_priv *a_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(a_priv->bus_interface);
++      struct usb_device *usb_dev;
+       struct agilent_82357a_register_pairlet write;
+       int retval;
++      if (!a_priv->bus_interface)
++              return -ENODEV;
++      usb_dev = interface_to_usbdev(a_priv->bus_interface);
+       write.address = FAST_TALKER_T1;
+       write.value = nanosec_to_fast_talker_bits(&nanosec);
+       retval = agilent_82357a_write_registers(a_priv, &write, 1);
+-- 
+2.39.5
+
diff --git a/queue-6.13/staging-gpib-fix-oops-after-disconnect-in-ni_usb.patch b/queue-6.13/staging-gpib-fix-oops-after-disconnect-in-ni_usb.patch
new file mode 100644 (file)
index 0000000..c0670c5
--- /dev/null
@@ -0,0 +1,360 @@
+From 754fe13f9d1a7f2853f063d9c58b4f40a56e6947 Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Sat, 22 Feb 2025 17:58:17 +0100
+Subject: staging: gpib: Fix Oops after disconnect in ni_usb
+
+From: Dave Penkler <dpenkler@gmail.com>
+
+[ Upstream commit a239c6e91b665f1837cf57b97fe638ef1baf2e78 ]
+
+If the usb dongle is disconnected subsequent calls to the
+driver cause a NULL dereference Oops as the bus_interface
+is set to NULL on disconnect.
+
+This problem was introduced by setting usb_dev from the bus_interface
+for dev_xxx messages.
+
+Previously bus_interface was checked for NULL only in the the functions
+directly calling usb_fill_bulk_urb or usb_control_msg.
+
+Check for valid bus_interface on all interface entry points
+and return -ENODEV if it is NULL.
+
+Fixes: 4934b98bb243 ("staging: gpib: Update messaging and usb_device refs in ni_usb")
+Cc: stable <stable@kernel.org>
+Signed-off-by: Dave Penkler <dpenkler@gmail.com>
+Link: https://lore.kernel.org/r/20250222165817.12856-1-dpenkler@gmail.com
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ drivers/staging/gpib/ni_usb/ni_usb_gpib.c | 93 ++++++++++++++++++-----
+ 1 file changed, 73 insertions(+), 20 deletions(-)
+
+diff --git a/drivers/staging/gpib/ni_usb/ni_usb_gpib.c b/drivers/staging/gpib/ni_usb/ni_usb_gpib.c
+index b6c28a28ee25d..7faae29b66e61 100644
+--- a/drivers/staging/gpib/ni_usb/ni_usb_gpib.c
++++ b/drivers/staging/gpib/ni_usb/ni_usb_gpib.c
+@@ -592,7 +592,7 @@ static int ni_usb_read(gpib_board_t *board, uint8_t *buffer, size_t length,
+ {
+       int retval, parse_retval;
+       struct ni_usb_priv *ni_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(ni_priv->bus_interface);
++      struct usb_device *usb_dev;
+       u8 *out_data, *in_data;
+       static const int out_data_length = 0x20;
+       int in_data_length;
+@@ -605,8 +605,11 @@ static int ni_usb_read(gpib_board_t *board, uint8_t *buffer, size_t length,
+       struct ni_usb_register reg;
+       *bytes_read = 0;
++      if (!ni_priv->bus_interface)
++              return -ENODEV;
+       if (length > max_read_length)
+               return -EINVAL;
++      usb_dev = interface_to_usbdev(ni_priv->bus_interface);
+       out_data = kmalloc(out_data_length, GFP_KERNEL);
+       if (!out_data)
+               return -ENOMEM;
+@@ -719,7 +722,7 @@ static int ni_usb_write(gpib_board_t *board, uint8_t *buffer, size_t length,
+ {
+       int retval;
+       struct ni_usb_priv *ni_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(ni_priv->bus_interface);
++      struct usb_device *usb_dev;
+       u8 *out_data, *in_data;
+       int out_data_length;
+       static const int in_data_length = 0x10;
+@@ -729,9 +732,11 @@ static int ni_usb_write(gpib_board_t *board, uint8_t *buffer, size_t length,
+       struct ni_usb_status_block status;
+       static const int max_write_length = 0xffff;
+-      *bytes_written = 0;
++      if (!ni_priv->bus_interface)
++              return -ENODEV;
+       if (length > max_write_length)
+               return -EINVAL;
++      usb_dev = interface_to_usbdev(ni_priv->bus_interface);
+       out_data_length = length + 0x10;
+       out_data = kmalloc(out_data_length, GFP_KERNEL);
+       if (!out_data)
+@@ -818,7 +823,7 @@ static int ni_usb_command_chunk(gpib_board_t *board, uint8_t *buffer, size_t len
+ {
+       int retval;
+       struct ni_usb_priv *ni_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(ni_priv->bus_interface);
++      struct usb_device *usb_dev;
+       u8 *out_data, *in_data;
+       int out_data_length;
+       static const int in_data_length = 0x10;
+@@ -830,8 +835,11 @@ static int ni_usb_command_chunk(gpib_board_t *board, uint8_t *buffer, size_t len
+       static const int max_command_length = 0x10;
+       *command_bytes_written = 0;
++      if (!ni_priv->bus_interface)
++              return -ENODEV;
+       if (length > max_command_length)
+               length = max_command_length;
++      usb_dev = interface_to_usbdev(ni_priv->bus_interface);
+       out_data_length = length + 0x10;
+       out_data = kmalloc(out_data_length, GFP_KERNEL);
+       if (!out_data)
+@@ -924,7 +932,7 @@ static int ni_usb_take_control(gpib_board_t *board, int synchronous)
+ {
+       int retval;
+       struct ni_usb_priv *ni_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(ni_priv->bus_interface);
++      struct usb_device *usb_dev;
+       u8 *out_data, *in_data;
+       static const int out_data_length = 0x10;
+       static const int  in_data_length = 0x10;
+@@ -932,6 +940,9 @@ static int ni_usb_take_control(gpib_board_t *board, int synchronous)
+       int i = 0;
+       struct ni_usb_status_block status;
++      if (!ni_priv->bus_interface)
++              return -ENODEV;
++      usb_dev = interface_to_usbdev(ni_priv->bus_interface);
+       out_data = kmalloc(out_data_length, GFP_KERNEL);
+       if (!out_data)
+               return -ENOMEM;
+@@ -982,7 +993,7 @@ static int ni_usb_go_to_standby(gpib_board_t *board)
+ {
+       int retval;
+       struct ni_usb_priv *ni_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(ni_priv->bus_interface);
++      struct usb_device *usb_dev;
+       u8 *out_data, *in_data;
+       static const int out_data_length = 0x10;
+       static const int  in_data_length = 0x20;
+@@ -990,6 +1001,9 @@ static int ni_usb_go_to_standby(gpib_board_t *board)
+       int i = 0;
+       struct ni_usb_status_block status;
++      if (!ni_priv->bus_interface)
++              return -ENODEV;
++      usb_dev = interface_to_usbdev(ni_priv->bus_interface);
+       out_data = kmalloc(out_data_length, GFP_KERNEL);
+       if (!out_data)
+               return -ENOMEM;
+@@ -1038,11 +1052,14 @@ static void ni_usb_request_system_control(gpib_board_t *board, int request_contr
+ {
+       int retval;
+       struct ni_usb_priv *ni_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(ni_priv->bus_interface);
++      struct usb_device *usb_dev;
+       int i = 0;
+       struct ni_usb_register writes[4];
+       unsigned int ibsta;
++      if (!ni_priv->bus_interface)
++              return; // -ENODEV;
++      usb_dev = interface_to_usbdev(ni_priv->bus_interface);
+       if (request_control) {
+               writes[i].device = NIUSB_SUBDEV_TNT4882;
+               writes[i].address = CMDR;
+@@ -1086,7 +1103,7 @@ static void ni_usb_interface_clear(gpib_board_t *board, int assert)
+ {
+       int retval;
+       struct ni_usb_priv *ni_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(ni_priv->bus_interface);
++      struct usb_device *usb_dev;
+       u8 *out_data, *in_data;
+       static const int out_data_length = 0x10;
+       static const int  in_data_length = 0x10;
+@@ -1094,7 +1111,10 @@ static void ni_usb_interface_clear(gpib_board_t *board, int assert)
+       int i = 0;
+       struct ni_usb_status_block status;
+-      // FIXME: we are going to pulse when assert is true, and ignore otherwise
++      if (!ni_priv->bus_interface)
++              return; // -ENODEV;
++      usb_dev = interface_to_usbdev(ni_priv->bus_interface);
++// FIXME: we are going to pulse when assert is true, and ignore otherwise
+       if (assert == 0)
+               return;
+       out_data = kmalloc(out_data_length, GFP_KERNEL);
+@@ -1132,10 +1152,13 @@ static void ni_usb_remote_enable(gpib_board_t *board, int enable)
+ {
+       int retval;
+       struct ni_usb_priv *ni_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(ni_priv->bus_interface);
++      struct usb_device *usb_dev;
+       struct ni_usb_register reg;
+       unsigned int ibsta;
++      if (!ni_priv->bus_interface)
++              return; // -ENODEV;
++      usb_dev = interface_to_usbdev(ni_priv->bus_interface);
+       reg.device = NIUSB_SUBDEV_TNT4882;
+       reg.address = nec7210_to_tnt4882_offset(AUXMR);
+       if (enable)
+@@ -1179,11 +1202,14 @@ static unsigned int ni_usb_update_status(gpib_board_t *board, unsigned int clear
+ {
+       int retval;
+       struct ni_usb_priv *ni_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(ni_priv->bus_interface);
++      struct usb_device *usb_dev;
+       static const int buffer_length = 8;
+       u8 *buffer;
+       struct ni_usb_status_block status;
++      if (!ni_priv->bus_interface)
++              return -ENODEV;
++      usb_dev = interface_to_usbdev(ni_priv->bus_interface);
+       buffer = kmalloc(buffer_length, GFP_KERNEL);
+       if (!buffer)
+               return board->status;
+@@ -1231,11 +1257,14 @@ static int ni_usb_primary_address(gpib_board_t *board, unsigned int address)
+ {
+       int retval;
+       struct ni_usb_priv *ni_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(ni_priv->bus_interface);
++      struct usb_device *usb_dev;
+       int i = 0;
+       struct ni_usb_register writes[2];
+       unsigned int ibsta;
++      if (!ni_priv->bus_interface)
++              return -ENODEV;
++      usb_dev = interface_to_usbdev(ni_priv->bus_interface);
+       writes[i].device = NIUSB_SUBDEV_TNT4882;
+       writes[i].address = nec7210_to_tnt4882_offset(ADR);
+       writes[i].value = address;
+@@ -1286,11 +1315,14 @@ static int ni_usb_secondary_address(gpib_board_t *board, unsigned int address, i
+ {
+       int retval;
+       struct ni_usb_priv *ni_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(ni_priv->bus_interface);
++      struct usb_device *usb_dev;
+       int i = 0;
+       struct ni_usb_register writes[3];
+       unsigned int ibsta;
++      if (!ni_priv->bus_interface)
++              return -ENODEV;
++      usb_dev = interface_to_usbdev(ni_priv->bus_interface);
+       i += ni_usb_write_sad(writes, address, enable);
+       retval = ni_usb_write_registers(ni_priv, writes, i, &ibsta);
+       if (retval < 0) {
+@@ -1305,7 +1337,7 @@ static int ni_usb_parallel_poll(gpib_board_t *board, uint8_t *result)
+ {
+       int retval;
+       struct ni_usb_priv *ni_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(ni_priv->bus_interface);
++      struct usb_device *usb_dev;
+       u8 *out_data, *in_data;
+       static const int out_data_length = 0x10;
+       static const int  in_data_length = 0x20;
+@@ -1314,6 +1346,9 @@ static int ni_usb_parallel_poll(gpib_board_t *board, uint8_t *result)
+       int j = 0;
+       struct ni_usb_status_block status;
++      if (!ni_priv->bus_interface)
++              return -ENODEV;
++      usb_dev = interface_to_usbdev(ni_priv->bus_interface);
+       out_data = kmalloc(out_data_length, GFP_KERNEL);
+       if (!out_data)
+               return -ENOMEM;
+@@ -1357,11 +1392,14 @@ static void ni_usb_parallel_poll_configure(gpib_board_t *board, uint8_t config)
+ {
+       int retval;
+       struct ni_usb_priv *ni_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(ni_priv->bus_interface);
++      struct usb_device *usb_dev;
+       int i = 0;
+       struct ni_usb_register writes[1];
+       unsigned int ibsta;
++      if (!ni_priv->bus_interface)
++              return; // -ENODEV;
++      usb_dev = interface_to_usbdev(ni_priv->bus_interface);
+       writes[i].device = NIUSB_SUBDEV_TNT4882;
+       writes[i].address = nec7210_to_tnt4882_offset(AUXMR);
+       writes[i].value = PPR | config;
+@@ -1379,11 +1417,14 @@ static void ni_usb_parallel_poll_response(gpib_board_t *board, int ist)
+ {
+       int retval;
+       struct ni_usb_priv *ni_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(ni_priv->bus_interface);
++      struct usb_device *usb_dev;
+       int i = 0;
+       struct ni_usb_register writes[1];
+       unsigned int ibsta;
++      if (!ni_priv->bus_interface)
++              return; // -ENODEV;
++      usb_dev = interface_to_usbdev(ni_priv->bus_interface);
+       writes[i].device = NIUSB_SUBDEV_TNT4882;
+       writes[i].address = nec7210_to_tnt4882_offset(AUXMR);
+       if (ist)
+@@ -1404,11 +1445,14 @@ static void ni_usb_serial_poll_response(gpib_board_t *board, u8 status)
+ {
+       int retval;
+       struct ni_usb_priv *ni_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(ni_priv->bus_interface);
++      struct usb_device *usb_dev;
+       int i = 0;
+       struct ni_usb_register writes[1];
+       unsigned int ibsta;
++      if (!ni_priv->bus_interface)
++              return; // -ENODEV;
++      usb_dev = interface_to_usbdev(ni_priv->bus_interface);
+       writes[i].device = NIUSB_SUBDEV_TNT4882;
+       writes[i].address = nec7210_to_tnt4882_offset(SPMR);
+       writes[i].value = status;
+@@ -1431,11 +1475,14 @@ static void ni_usb_return_to_local(gpib_board_t *board)
+ {
+       int retval;
+       struct ni_usb_priv *ni_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(ni_priv->bus_interface);
++      struct usb_device *usb_dev;
+       int i = 0;
+       struct ni_usb_register writes[1];
+       unsigned int ibsta;
++      if (!ni_priv->bus_interface)
++              return; // -ENODEV;
++      usb_dev = interface_to_usbdev(ni_priv->bus_interface);
+       writes[i].device = NIUSB_SUBDEV_TNT4882;
+       writes[i].address = nec7210_to_tnt4882_offset(AUXMR);
+       writes[i].value = AUX_RTL;
+@@ -1453,7 +1500,7 @@ static int ni_usb_line_status(const gpib_board_t *board)
+ {
+       int retval;
+       struct ni_usb_priv *ni_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(ni_priv->bus_interface);
++      struct usb_device *usb_dev;
+       u8 *out_data, *in_data;
+       static const int out_data_length = 0x20;
+       static const int  in_data_length = 0x20;
+@@ -1463,6 +1510,9 @@ static int ni_usb_line_status(const gpib_board_t *board)
+       int line_status = ValidALL;
+       // NI windows driver reads 0xd(HSSEL), 0xc (ARD0), 0x1f (BSR)
++      if (!ni_priv->bus_interface)
++              return -ENODEV;
++      usb_dev = interface_to_usbdev(ni_priv->bus_interface);
+       out_data = kmalloc(out_data_length, GFP_KERNEL);
+       if (!out_data)
+               return -ENOMEM;
+@@ -1569,12 +1619,15 @@ static unsigned int ni_usb_t1_delay(gpib_board_t *board, unsigned int nano_sec)
+ {
+       int retval;
+       struct ni_usb_priv *ni_priv = board->private_data;
+-      struct usb_device *usb_dev = interface_to_usbdev(ni_priv->bus_interface);
++      struct usb_device *usb_dev;
+       struct ni_usb_register writes[3];
+       unsigned int ibsta;
+       unsigned int actual_ns;
+       int i;
++      if (!ni_priv->bus_interface)
++              return -ENODEV;
++      usb_dev = interface_to_usbdev(ni_priv->bus_interface);
+       i = ni_usb_setup_t1_delay(writes, nano_sec, &actual_ns);
+       retval = ni_usb_write_registers(ni_priv, writes, i, &ibsta);
+       if (retval < 0) {
+-- 
+2.39.5
+
diff --git a/queue-6.13/staging-gpib-modify-gpib_register_driver-to-return-e.patch b/queue-6.13/staging-gpib-modify-gpib_register_driver-to-return-e.patch
new file mode 100644 (file)
index 0000000..5d61619
--- /dev/null
@@ -0,0 +1,69 @@
+From 33b1fe396a16e7f327622c72e5e937a3c629ea5b Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Tue, 31 Dec 2024 00:26:21 +0530
+Subject: staging: gpib: Modify gpib_register_driver() to return error if it
+ fails
+
+From: Nihar Chaithanya <niharchaithanya@gmail.com>
+
+[ Upstream commit e999bd2a897e7d70fa1fca6b80873529532322fe ]
+
+The function gpib_register_driver() can fail if kmalloc() fails,
+but it doesn't return any error if that happens.
+
+Modify the function to return error i.e int. Return the appropriate
+error code if it fails. Remove the pr_info() statement.
+
+Signed-off-by: Nihar Chaithanya <niharchaithanya@gmail.com>
+Link: https://lore.kernel.org/r/20241230185633.175690-2-niharchaithanya@gmail.com
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Stable-dep-of: a239c6e91b66 ("staging: gpib: Fix Oops after disconnect in ni_usb")
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ drivers/staging/gpib/common/gpib_os.c | 7 ++++---
+ drivers/staging/gpib/include/gpibP.h  | 2 +-
+ 2 files changed, 5 insertions(+), 4 deletions(-)
+
+diff --git a/drivers/staging/gpib/common/gpib_os.c b/drivers/staging/gpib/common/gpib_os.c
+index 0962729d7dfef..982a2fe68cf2a 100644
+--- a/drivers/staging/gpib/common/gpib_os.c
++++ b/drivers/staging/gpib/common/gpib_os.c
+@@ -2044,18 +2044,19 @@ void init_gpib_descriptor(gpib_descriptor_t *desc)
+       atomic_set(&desc->io_in_progress, 0);
+ }
+-void gpib_register_driver(gpib_interface_t *interface, struct module *provider_module)
++int gpib_register_driver(gpib_interface_t *interface, struct module *provider_module)
+ {
+       struct gpib_interface_list_struct *entry;
+       entry = kmalloc(sizeof(*entry), GFP_KERNEL);
+       if (!entry)
+-              return;
++              return -ENOMEM;
+       entry->interface = interface;
+       entry->module = provider_module;
+       list_add(&entry->list, &registered_drivers);
+-      pr_info("gpib: registered %s interface\n", interface->name);
++
++      return 0;
+ }
+ EXPORT_SYMBOL(gpib_register_driver);
+diff --git a/drivers/staging/gpib/include/gpibP.h b/drivers/staging/gpib/include/gpibP.h
+index b97da577ba332..d35fdd391f7e1 100644
+--- a/drivers/staging/gpib/include/gpibP.h
++++ b/drivers/staging/gpib/include/gpibP.h
+@@ -18,7 +18,7 @@
+ #include <linux/interrupt.h>
+ #include <linux/io.h>
+-void gpib_register_driver(gpib_interface_t *interface, struct module *mod);
++int gpib_register_driver(gpib_interface_t *interface, struct module *mod);
+ void gpib_unregister_driver(gpib_interface_t *interface);
+ struct pci_dev *gpib_pci_get_device(const gpib_board_config_t *config, unsigned int vendor_id,
+                                   unsigned int device_id, struct pci_dev *from);
+-- 
+2.39.5
+
diff --git a/queue-6.13/staging-gpib-ni_usb-console-messaging-cleanup.patch b/queue-6.13/staging-gpib-ni_usb-console-messaging-cleanup.patch
new file mode 100644 (file)
index 0000000..d6e5f04
--- /dev/null
@@ -0,0 +1,1310 @@
+From 10c806ca829fd124367e7034775d20dd8f36c54b Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Fri, 14 Feb 2025 12:47:05 +0100
+Subject: staging: gpib: ni_usb console messaging cleanup
+
+From: Dave Penkler <dpenkler@gmail.com>
+
+[ Upstream commit 18ce5b5d9167bffce02550a85c7c3316a05ea598 ]
+
+Enable module name to be printed in pr_xxx and dev_xxx
+Use DRV_NAME defined as KBUILD_MODNAME instead of hard coded
+string "ni_usb_gpib" in usb_driver struct.
+
+Remove __func__ parameter from pr_err and dev_err.
+
+Remove __func__ parameter from dev_dbg as this can be
+enabled by dynamic debug.
+
+Remove commented printk's and dev_err's.
+
+Remove kmalloc failed messages.
+
+Remove buffer over run bug dev_err message as this just checks
+for a bug in the driver which does not exist.
+
+Remove read/write length too long messages and return -EINVAL
+
+Change dev_info to dev_dbg where possible.
+
+Move attach message to the end of attach function.
+
+Remove buffer overrun message. Use actual array indeces
+instead of i and i++ to make code clear and check redundnant.
+
+Remove module init and exit pr_info's.
+
+Signed-off-by: Dave Penkler <dpenkler@gmail.com>
+Link: https://lore.kernel.org/r/20250214114708.28947-15-dpenkler@gmail.com
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Stable-dep-of: a239c6e91b66 ("staging: gpib: Fix Oops after disconnect in ni_usb")
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ drivers/staging/gpib/ni_usb/ni_usb_gpib.c | 425 ++++++++++------------
+ 1 file changed, 189 insertions(+), 236 deletions(-)
+
+diff --git a/drivers/staging/gpib/ni_usb/ni_usb_gpib.c b/drivers/staging/gpib/ni_usb/ni_usb_gpib.c
+index 3c4132fd6de95..b6c28a28ee25d 100644
+--- a/drivers/staging/gpib/ni_usb/ni_usb_gpib.c
++++ b/drivers/staging/gpib/ni_usb/ni_usb_gpib.c
+@@ -5,6 +5,10 @@
+  *    copyright                  : (C) 2004 by Frank Mori Hess
+  ***************************************************************************/
++#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
++#define dev_fmt pr_fmt
++#define DRV_NAME KBUILD_MODNAME
++
+ #include <linux/kernel.h>
+ #include <linux/module.h>
+ #include <linux/slab.h>
+@@ -75,7 +79,7 @@ static unsigned short ni_usb_timeout_code(unsigned int usec)
+        */
+       else if (usec <= 1000000000)
+               return 0x02;
+-      pr_err("%s: bug? usec is greater than 1e9\n", __func__);
++      pr_err("bug? usec is greater than 1e9\n");
+       return 0xf0;
+ }
+@@ -83,8 +87,6 @@ static void ni_usb_bulk_complete(struct urb *urb)
+ {
+       struct ni_usb_urb_ctx *context = urb->context;
+-//    printk("debug: %s: status=0x%x, error_count=%i, actual_length=%i\n",  __func__,
+-//            urb->status, urb->error_count, urb->actual_length);
+       complete(&context->complete);
+ }
+@@ -137,8 +139,8 @@ static int ni_usb_nonblocking_send_bulk_msg(struct ni_usb_priv *ni_priv, void *d
+               del_timer_sync(&ni_priv->bulk_timer);
+               usb_free_urb(ni_priv->bulk_urb);
+               ni_priv->bulk_urb = NULL;
+-              dev_err(&usb_dev->dev, "%s: failed to submit bulk out urb, retval=%i\n",
+-                      __func__, retval);
++              dev_err(&usb_dev->dev, "failed to submit bulk out urb, retval=%i\n",
++                      retval);
+               mutex_unlock(&ni_priv->bulk_transfer_lock);
+               return retval;
+       }
+@@ -146,7 +148,7 @@ static int ni_usb_nonblocking_send_bulk_msg(struct ni_usb_priv *ni_priv, void *d
+       wait_for_completion(&context->complete);    // wait for ni_usb_bulk_complete
+       if (context->timed_out) {
+               usb_kill_urb(ni_priv->bulk_urb);
+-              dev_err(&usb_dev->dev, "%s: killed urb due to timeout\n", __func__);
++              dev_err(&usb_dev->dev, "killed urb due to timeout\n");
+               retval = -ETIMEDOUT;
+       } else {
+               retval = ni_priv->bulk_urb->status;
+@@ -218,14 +220,12 @@ static int ni_usb_nonblocking_receive_bulk_msg(struct ni_usb_priv *ni_priv,
+       if (timeout_msecs)
+               mod_timer(&ni_priv->bulk_timer, jiffies + msecs_to_jiffies(timeout_msecs));
+-      //printk("%s: submitting urb\n", __func__);
+       retval = usb_submit_urb(ni_priv->bulk_urb, GFP_KERNEL);
+       if (retval) {
+               del_timer_sync(&ni_priv->bulk_timer);
+               usb_free_urb(ni_priv->bulk_urb);
+               ni_priv->bulk_urb = NULL;
+-              dev_err(&usb_dev->dev, "%s: failed to submit bulk out urb, retval=%i\n",
+-                      __func__, retval);
++              dev_err(&usb_dev->dev, "failed to submit bulk in urb, retval=%i\n", retval);
+               mutex_unlock(&ni_priv->bulk_transfer_lock);
+               return retval;
+       }
+@@ -250,7 +250,7 @@ static int ni_usb_nonblocking_receive_bulk_msg(struct ni_usb_priv *ni_priv,
+       }
+       if (context->timed_out) {
+               usb_kill_urb(ni_priv->bulk_urb);
+-              dev_err(&usb_dev->dev, "%s: killed urb due to timeout\n", __func__);
++              dev_err(&usb_dev->dev, "killed urb due to timeout\n");
+               retval = -ETIMEDOUT;
+       } else {
+               if (ni_priv->bulk_urb->status)
+@@ -330,14 +330,14 @@ static void ni_usb_soft_update_status(gpib_board_t *board, unsigned int ni_usb_i
+       ni_priv->monitored_ibsta_bits &= ~ni_usb_ibsta;
+       need_monitoring_bits &= ~ni_priv->monitored_ibsta_bits; /* mm - monitored set */
+       spin_unlock_irqrestore(&board->spinlock, flags);
+-      dev_dbg(&usb_dev->dev, "%s: need_monitoring_bits=0x%x\n", __func__, need_monitoring_bits);
++      dev_dbg(&usb_dev->dev, "need_monitoring_bits=0x%x\n", need_monitoring_bits);
+       if (need_monitoring_bits & ~ni_usb_ibsta)
+               ni_usb_set_interrupt_monitor(board, ni_usb_ibsta_monitor_mask);
+       else if (need_monitoring_bits & ni_usb_ibsta)
+               wake_up_interruptible(&board->wait);
+-      dev_dbg(&usb_dev->dev, "%s: ni_usb_ibsta=0x%x\n", __func__, ni_usb_ibsta);
++      dev_dbg(&usb_dev->dev, "ibsta=0x%x\n", ni_usb_ibsta);
+ }
+ static int ni_usb_parse_status_block(const u8 *buffer, struct ni_usb_status_block *status)
+@@ -371,7 +371,7 @@ static int ni_usb_parse_register_read_block(const u8 *raw_data, unsigned int *re
+               int k;
+               if (raw_data[i++] != NIUSB_REGISTER_READ_DATA_START_ID) {
+-                      pr_err("%s: parse error: wrong start id\n", __func__);
++                      pr_err("parse error: wrong start id\n");
+                       unexpected = 1;
+               }
+               for (k = 0; k < results_per_chunk && j < num_results; ++k)
+@@ -380,18 +380,18 @@ static int ni_usb_parse_register_read_block(const u8 *raw_data, unsigned int *re
+       while (i % 4)
+               i++;
+       if (raw_data[i++] != NIUSB_REGISTER_READ_DATA_END_ID) {
+-              pr_err("%s: parse error: wrong end id\n", __func__);
++              pr_err("parse error: wrong end id\n");
+               unexpected = 1;
+       }
+       if (raw_data[i++] % results_per_chunk != num_results % results_per_chunk) {
+-              pr_err("%s: parse error: wrong count=%i for NIUSB_REGISTER_READ_DATA_END\n",
+-                     __func__, (int)raw_data[i - 1]);
++              pr_err("parse error: wrong count=%i for NIUSB_REGISTER_READ_DATA_END\n",
++                     (int)raw_data[i - 1]);
+               unexpected = 1;
+       }
+       while (i % 4) {
+               if (raw_data[i++] != 0) {
+-                      pr_err("%s: unexpected data: raw_data[%i]=0x%x, expected 0\n",
+-                             __func__, i - 1, (int)raw_data[i - 1]);
++                      pr_err("unexpected data: raw_data[%i]=0x%x, expected 0\n",
++                             i - 1, (int)raw_data[i - 1]);
+                       unexpected = 1;
+               }
+       }
+@@ -408,9 +408,8 @@ static int ni_usb_parse_termination_block(const u8 *buffer)
+           buffer[i++] != 0x0 ||
+           buffer[i++] != 0x0 ||
+           buffer[i++] != 0x0) {
+-              pr_err("%s: received unexpected termination block\n", __func__);
+-              pr_err(" expected: 0x%x 0x%x 0x%x 0x%x\n",
+-                     NIUSB_TERM_ID, 0x0, 0x0, 0x0);
++              pr_err("received unexpected termination block\n");
++              pr_err(" expected: 0x%x 0x%x 0x%x 0x%x\n", NIUSB_TERM_ID, 0x0, 0x0, 0x0);
+               pr_err(" received: 0x%x 0x%x 0x%x 0x%x\n",
+                      buffer[i - 4], buffer[i - 3], buffer[i - 2], buffer[i - 1]);
+       }
+@@ -438,12 +437,12 @@ static int parse_board_ibrd_readback(const u8 *raw_data, struct ni_usb_status_bl
+               } else if (raw_data[i] == NIUSB_IBRD_EXTENDED_DATA_ID) {
+                       data_block_length = ibrd_extended_data_block_length;
+                       if (raw_data[++i] !=  0)        {
+-                              pr_err("%s: unexpected data: raw_data[%i]=0x%x, expected 0\n",
+-                                     __func__, i, (int)raw_data[i]);
++                              pr_err("unexpected data: raw_data[%i]=0x%x, expected 0\n",
++                                     i, (int)raw_data[i]);
+                               unexpected = 1;
+                       }
+               } else {
+-                      pr_err("%s: logic bug!\n", __func__);
++                      pr_err("Unexpected NIUSB_IBRD ID\n");
+                       return -EINVAL;
+               }
+               ++i;
+@@ -457,7 +456,7 @@ static int parse_board_ibrd_readback(const u8 *raw_data, struct ni_usb_status_bl
+       }
+       i += ni_usb_parse_status_block(&raw_data[i], status);
+       if (status->id != NIUSB_IBRD_STATUS_ID) {
+-              pr_err("%s: bug: status->id=%i, != ibrd_status_id\n", __func__, status->id);
++              pr_err("bug: status->id=%i, != ibrd_status_id\n", status->id);
+               return -EIO;
+       }
+       adr1_bits = raw_data[i++];
+@@ -468,29 +467,28 @@ static int parse_board_ibrd_readback(const u8 *raw_data, struct ni_usb_status_bl
+               *actual_bytes_read = 0;
+       }
+       if (*actual_bytes_read > j)
+-              pr_err("%s: bug: discarded data. actual_bytes_read=%i, j=%i\n",
+-                     __func__, *actual_bytes_read, j);
++              pr_err("bug: discarded data. actual_bytes_read=%i, j=%i\n", *actual_bytes_read, j);
+       for (k = 0; k < 2; k++)
+               if (raw_data[i++] != 0) {
+-                      pr_err("%s: unexpected data: raw_data[%i]=0x%x, expected 0\n",
+-                             __func__, i - 1, (int)raw_data[i - 1]);
++                      pr_err("unexpected data: raw_data[%i]=0x%x, expected 0\n",
++                             i - 1, (int)raw_data[i - 1]);
+                       unexpected = 1;
+               }
+       i += ni_usb_parse_status_block(&raw_data[i], &register_write_status);
+       if (register_write_status.id != NIUSB_REG_WRITE_ID) {
+-              pr_err("%s: unexpected data: register write status id=0x%x, expected 0x%x\n",
+-                     __func__, register_write_status.id, NIUSB_REG_WRITE_ID);
++              pr_err("unexpected data: register write status id=0x%x, expected 0x%x\n",
++                     register_write_status.id, NIUSB_REG_WRITE_ID);
+               unexpected = 1;
+       }
+       if (raw_data[i++] != 2) {
+-              pr_err("%s: unexpected data: register write count=%i, expected 2\n",
+-                     __func__, (int)raw_data[i - 1]);
++              pr_err("unexpected data: register write count=%i, expected 2\n",
++                     (int)raw_data[i - 1]);
+               unexpected = 1;
+       }
+       for (k = 0; k < 3; k++)
+               if (raw_data[i++] != 0) {
+-                      pr_err("%s: unexpected data: raw_data[%i]=0x%x, expected 0\n",
+-                             __func__, i - 1, (int)raw_data[i - 1]);
++                      pr_err("unexpected data: raw_data[%i]=0x%x, expected 0\n",
++                             i - 1, (int)raw_data[i - 1]);
+                       unexpected = 1;
+               }
+       i += ni_usb_parse_termination_block(&raw_data[i]);
+@@ -530,18 +528,14 @@ static int ni_usb_write_registers(struct ni_usb_priv *ni_priv,
+       out_data_length = num_writes * bytes_per_write + 0x10;
+       out_data = kmalloc(out_data_length, GFP_KERNEL);
+-      if (!out_data)  {
+-              dev_err(&usb_dev->dev, "%s: kmalloc failed\n", __func__);
++      if (!out_data)
+               return -ENOMEM;
+-      }
+       i += ni_usb_bulk_register_write_header(&out_data[i], num_writes);
+       for (j = 0; j < num_writes; j++)
+               i += ni_usb_bulk_register_write(&out_data[i], writes[j]);
+       while (i % 4)
+               out_data[i++] = 0x00;
+       i += ni_usb_bulk_termination(&out_data[i]);
+-      if (i > out_data_length)
+-              dev_err(&usb_dev->dev, "%s: bug! buffer overrun\n", __func__);
+       mutex_lock(&ni_priv->addressed_transfer_lock);
+@@ -549,22 +543,21 @@ static int ni_usb_write_registers(struct ni_usb_priv *ni_priv,
+       kfree(out_data);
+       if (retval) {
+               mutex_unlock(&ni_priv->addressed_transfer_lock);
+-              dev_err(&usb_dev->dev, "%s: ni_usb_send_bulk_msg returned %i, bytes_written=%i, i=%i\n",
+-                      __func__, retval, bytes_written, i);
++              dev_err(&usb_dev->dev, "send_bulk_msg returned %i, bytes_written=%i, i=%i\n",
++                      retval, bytes_written, i);
+               return retval;
+       }
+       in_data = kmalloc(in_data_length, GFP_KERNEL);
+       if (!in_data) {
+               mutex_unlock(&ni_priv->addressed_transfer_lock);
+-              dev_err(&usb_dev->dev, "%s: kmalloc failed\n", __func__);
+               return -ENOMEM;
+       }
+       retval = ni_usb_receive_bulk_msg(ni_priv, in_data, in_data_length, &bytes_read, 1000, 0);
+       if (retval || bytes_read != 16) {
+               mutex_unlock(&ni_priv->addressed_transfer_lock);
+-              dev_err(&usb_dev->dev, "%s: ni_usb_receive_bulk_msg returned %i, bytes_read=%i\n",
+-                      __func__, retval, bytes_read);
++              dev_err(&usb_dev->dev, "receive_bulk_msg returned %i, bytes_read=%i\n",
++                      retval, bytes_read);
+               ni_usb_dump_raw_block(in_data, bytes_read);
+               kfree(in_data);
+               return retval;
+@@ -576,18 +569,16 @@ static int ni_usb_write_registers(struct ni_usb_priv *ni_priv,
+       //FIXME parse extra 09 status bits and termination
+       kfree(in_data);
+       if (status.id != NIUSB_REG_WRITE_ID) {
+-              dev_err(&usb_dev->dev, "%s: parse error, id=0x%x != NIUSB_REG_WRITE_ID\n",
+-                      __func__, status.id);
++              dev_err(&usb_dev->dev, "parse error, id=0x%x != NIUSB_REG_WRITE_ID\n", status.id);
+               return -EIO;
+       }
+       if (status.error_code) {
+-              dev_err(&usb_dev->dev, "%s: nonzero error code 0x%x\n",
+-                      __func__, status.error_code);
++              dev_err(&usb_dev->dev, "nonzero error code 0x%x\n", status.error_code);
+               return -EIO;
+       }
+       if (reg_writes_completed != num_writes) {
+-              dev_err(&usb_dev->dev, "%s: reg_writes_completed=%i, num_writes=%i\n",
+-                      __func__, reg_writes_completed, num_writes);
++              dev_err(&usb_dev->dev, "reg_writes_completed=%i, num_writes=%i\n",
++                      reg_writes_completed, num_writes);
+               return -EIO;
+       }
+       if (ibsta)
+@@ -614,10 +605,8 @@ static int ni_usb_read(gpib_board_t *board, uint8_t *buffer, size_t length,
+       struct ni_usb_register reg;
+       *bytes_read = 0;
+-      if (length > max_read_length)   {
+-              length = max_read_length;
+-              dev_err(&usb_dev->dev, "%s: read length too long\n", __func__);
+-      }
++      if (length > max_read_length)
++              return -EINVAL;
+       out_data = kmalloc(out_data_length, GFP_KERNEL);
+       if (!out_data)
+               return -ENOMEM;
+@@ -649,8 +638,8 @@ static int ni_usb_read(gpib_board_t *board, uint8_t *buffer, size_t length,
+       if (retval || usb_bytes_written != i) {
+               if (retval == 0)
+                       retval = -EIO;
+-              dev_err(&usb_dev->dev, "%s: ni_usb_send_bulk_msg returned %i, usb_bytes_written=%i, i=%i\n",
+-                      __func__, retval, usb_bytes_written, i);
++              dev_err(&usb_dev->dev, "send_bulk_msg returned %i, usb_bytes_written=%i, i=%i\n",
++                      retval, usb_bytes_written, i);
+               mutex_unlock(&ni_priv->addressed_transfer_lock);
+               return retval;
+       }
+@@ -668,8 +657,8 @@ static int ni_usb_read(gpib_board_t *board, uint8_t *buffer, size_t length,
+       if (retval == -ERESTARTSYS) {
+       } else if (retval) {
+-              dev_err(&usb_dev->dev, "%s: ni_usb_receive_bulk_msg returned %i, usb_bytes_read=%i\n",
+-                      __func__, retval, usb_bytes_read);
++              dev_err(&usb_dev->dev, "receive_bulk_msg returned %i, usb_bytes_read=%i\n",
++                      retval, usb_bytes_read);
+               kfree(in_data);
+               return retval;
+       }
+@@ -677,14 +666,14 @@ static int ni_usb_read(gpib_board_t *board, uint8_t *buffer, size_t length,
+       if (parse_retval != usb_bytes_read) {
+               if (parse_retval >= 0)
+                       parse_retval = -EIO;
+-              dev_err(&usb_dev->dev, "%s: retval=%i usb_bytes_read=%i\n",
+-                      __func__, parse_retval, usb_bytes_read);
++              dev_err(&usb_dev->dev, "retval=%i usb_bytes_read=%i\n",
++                      parse_retval, usb_bytes_read);
+               kfree(in_data);
+               return parse_retval;
+       }
+       if (actual_length != length - status.count) {
+-              dev_err(&usb_dev->dev, "%s: actual_length=%i expected=%li\n",
+-                      __func__, actual_length, (long)(length - status.count));
++              dev_err(&usb_dev->dev, "actual_length=%i expected=%li\n",
++                      actual_length, (long)(length - status.count));
+               ni_usb_dump_raw_block(in_data, usb_bytes_read);
+       }
+       kfree(in_data);
+@@ -699,7 +688,7 @@ static int ni_usb_read(gpib_board_t *board, uint8_t *buffer, size_t length,
+               break;
+       case NIUSB_ATN_STATE_ERROR:
+               retval = -EIO;
+-              dev_err(&usb_dev->dev, "%s: read when ATN set\n", __func__);
++              dev_err(&usb_dev->dev, "read when ATN set\n");
+               break;
+       case NIUSB_ADDRESSING_ERROR:
+               retval = -EIO;
+@@ -708,12 +697,11 @@ static int ni_usb_read(gpib_board_t *board, uint8_t *buffer, size_t length,
+               retval = -ETIMEDOUT;
+               break;
+       case NIUSB_EOSMODE_ERROR:
+-              dev_err(&usb_dev->dev, "%s: driver bug, we should have been able to avoid NIUSB_EOSMODE_ERROR.\n",
+-                      __func__);
++              dev_err(&usb_dev->dev, "driver bug, we should have been able to avoid NIUSB_EOSMODE_ERROR.\n");
+               retval = -EINVAL;
+               break;
+       default:
+-              dev_err(&usb_dev->dev, "%s: unknown error code=%i\n", __func__, status.error_code);
++              dev_err(&usb_dev->dev, "unknown error code=%i\n",  status.error_code);
+               retval = -EIO;
+               break;
+       }
+@@ -742,11 +730,8 @@ static int ni_usb_write(gpib_board_t *board, uint8_t *buffer, size_t length,
+       static const int max_write_length = 0xffff;
+       *bytes_written = 0;
+-      if (length > max_write_length) {
+-              length = max_write_length;
+-              send_eoi = 0;
+-              dev_err(&usb_dev->dev, "%s: write length too long\n", __func__);
+-      }
++      if (length > max_write_length)
++              return -EINVAL;
+       out_data_length = length + 0x10;
+       out_data = kmalloc(out_data_length, GFP_KERNEL);
+       if (!out_data)
+@@ -777,8 +762,8 @@ static int ni_usb_write(gpib_board_t *board, uint8_t *buffer, size_t length,
+       kfree(out_data);
+       if (retval || usb_bytes_written != i)   {
+               mutex_unlock(&ni_priv->addressed_transfer_lock);
+-              dev_err(&usb_dev->dev, "%s: ni_usb_send_bulk_msg returned %i, usb_bytes_written=%i, i=%i\n",
+-                      __func__, retval, usb_bytes_written, i);
++              dev_err(&usb_dev->dev, "send_bulk_msg returned %i, usb_bytes_written=%i, i=%i\n",
++                      retval, usb_bytes_written, i);
+               return retval;
+       }
+@@ -791,8 +776,8 @@ static int ni_usb_write(gpib_board_t *board, uint8_t *buffer, size_t length,
+       mutex_unlock(&ni_priv->addressed_transfer_lock);
+       if ((retval && retval != -ERESTARTSYS) || usb_bytes_read != 12) {
+-              dev_err(&usb_dev->dev, "%s: ni_usb_receive_bulk_msg returned %i, usb_bytes_read=%i\n",
+-                      __func__, retval, usb_bytes_read);
++              dev_err(&usb_dev->dev, "receive_bulk_msg returned %i, usb_bytes_read=%i\n",
++                      retval, usb_bytes_read);
+               kfree(in_data);
+               return retval;
+       }
+@@ -808,8 +793,8 @@ static int ni_usb_write(gpib_board_t *board, uint8_t *buffer, size_t length,
+                */
+               break;
+       case NIUSB_ADDRESSING_ERROR:
+-              dev_err(&usb_dev->dev, "%s: Addressing error retval %d error code=%i\n",
+-                      __func__, retval, status.error_code);
++              dev_err(&usb_dev->dev, "Addressing error retval %d error code=%i\n",
++                      retval, status.error_code);
+               retval = -ENXIO;
+               break;
+       case NIUSB_NO_LISTENER_ERROR:
+@@ -819,8 +804,7 @@ static int ni_usb_write(gpib_board_t *board, uint8_t *buffer, size_t length,
+               retval = -ETIMEDOUT;
+               break;
+       default:
+-              dev_err(&usb_dev->dev, "%s: unknown error code=%i\n",
+-                      __func__, status.error_code);
++              dev_err(&usb_dev->dev, "unknown error code=%i\n", status.error_code);
+               retval = -EPIPE;
+               break;
+       }
+@@ -871,8 +855,8 @@ static int ni_usb_command_chunk(gpib_board_t *board, uint8_t *buffer, size_t len
+       kfree(out_data);
+       if (retval || bytes_written != i) {
+               mutex_unlock(&ni_priv->addressed_transfer_lock);
+-              dev_err(&usb_dev->dev, "%s: ni_usb_send_bulk_msg returned %i, bytes_written=%i, i=%i\n",
+-                      __func__, retval, bytes_written, i);
++              dev_err(&usb_dev->dev, "send_bulk_msg returned %i, bytes_written=%i, i=%i\n",
++                      retval, bytes_written, i);
+               return retval;
+       }
+@@ -888,8 +872,8 @@ static int ni_usb_command_chunk(gpib_board_t *board, uint8_t *buffer, size_t len
+       mutex_unlock(&ni_priv->addressed_transfer_lock);
+       if ((retval && retval != -ERESTARTSYS) || bytes_read != 12) {
+-              dev_err(&usb_dev->dev, "%s: ni_usb_receive_bulk_msg returned %i, bytes_read=%i\n",
+-                      __func__, retval, bytes_read);
++              dev_err(&usb_dev->dev, "receive_bulk_msg returned %i, bytes_read=%i\n",
++                      retval, bytes_read);
+               kfree(in_data);
+               return retval;
+       }
+@@ -907,12 +891,12 @@ static int ni_usb_command_chunk(gpib_board_t *board, uint8_t *buffer, size_t len
+       case NIUSB_NO_BUS_ERROR:
+               return -ENOTCONN;
+       case NIUSB_EOSMODE_ERROR:
+-              dev_err(&usb_dev->dev, "%s: got eosmode error.  Driver bug?\n", __func__);
++              dev_err(&usb_dev->dev, "got eosmode error. Driver bug?\n");
+               return -EIO;
+       case NIUSB_TIMEOUT_ERROR:
+               return -ETIMEDOUT;
+       default:
+-              dev_err(&usb_dev->dev, "%s: unknown error code=%i\n", __func__, status.error_code);
++              dev_err(&usb_dev->dev, "unknown error code=%i\n", status.error_code);
+               return -EIO;
+       }
+       ni_usb_soft_update_status(board, status.ibsta, 0);
+@@ -966,15 +950,14 @@ static int ni_usb_take_control(gpib_board_t *board, int synchronous)
+       kfree(out_data);
+       if (retval || bytes_written != i) {
+               mutex_unlock(&ni_priv->addressed_transfer_lock);
+-              dev_err(&usb_dev->dev, "%s: ni_usb_send_bulk_msg returned %i, bytes_written=%i, i=%i\n",
+-                      __func__, retval, bytes_written, i);
++              dev_err(&usb_dev->dev, "send_bulk_msg returned %i, bytes_written=%i, i=%i\n",
++                      retval, bytes_written, i);
+               return retval;
+       }
+       in_data = kmalloc(in_data_length, GFP_KERNEL);
+       if (!in_data) {
+               mutex_unlock(&ni_priv->addressed_transfer_lock);
+-              dev_err(&usb_dev->dev, "%s: kmalloc failed\n", __func__);
+               return -ENOMEM;
+       }
+       retval = ni_usb_receive_bulk_msg(ni_priv, in_data, in_data_length, &bytes_read, 1000, 1);
+@@ -984,8 +967,8 @@ static int ni_usb_take_control(gpib_board_t *board, int synchronous)
+       if ((retval && retval != -ERESTARTSYS) || bytes_read != 12) {
+               if (retval == 0)
+                       retval = -EIO;
+-              dev_err(&usb_dev->dev, "%s: ni_usb_receive_bulk_msg returned %i, bytes_read=%i\n",
+-                      __func__, retval, bytes_read);
++              dev_err(&usb_dev->dev, "receive_bulk_msg returned %i, bytes_read=%i\n",
++                      retval, bytes_read);
+               kfree(in_data);
+               return retval;
+       }
+@@ -1023,15 +1006,14 @@ static int ni_usb_go_to_standby(gpib_board_t *board)
+       kfree(out_data);
+       if (retval || bytes_written != i) {
+               mutex_unlock(&ni_priv->addressed_transfer_lock);
+-              dev_err(&usb_dev->dev, "%s: ni_usb_send_bulk_msg returned %i, bytes_written=%i, i=%i\n",
+-                      __func__, retval, bytes_written, i);
++              dev_err(&usb_dev->dev, "send_bulk_msg returned %i, bytes_written=%i, i=%i\n",
++                      retval, bytes_written, i);
+               return retval;
+       }
+       in_data = kmalloc(in_data_length, GFP_KERNEL);
+       if (!in_data) {
+               mutex_unlock(&ni_priv->addressed_transfer_lock);
+-              dev_err(&usb_dev->dev, "%s: kmalloc failed\n", __func__);
+               return -ENOMEM;
+       }
+       retval = ni_usb_receive_bulk_msg(ni_priv, in_data, in_data_length, &bytes_read, 1000, 0);
+@@ -1039,16 +1021,15 @@ static int ni_usb_go_to_standby(gpib_board_t *board)
+       mutex_unlock(&ni_priv->addressed_transfer_lock);
+       if (retval || bytes_read != 12) {
+-              dev_err(&usb_dev->dev, "%s: ni_usb_receive_bulk_msg returned %i, bytes_read=%i\n",
+-                      __func__, retval, bytes_read);
++              dev_err(&usb_dev->dev, "receive_bulk_msg returned %i, bytes_read=%i\n",
++                      retval, bytes_read);
+               kfree(in_data);
+               return retval;
+       }
+       ni_usb_parse_status_block(in_data, &status);
+       kfree(in_data);
+       if (status.id != NIUSB_IBGTS_ID)
+-              dev_err(&usb_dev->dev, "%s: bug: status.id 0x%x != INUSB_IBGTS_ID\n",
+-                      __func__, status.id);
++              dev_err(&usb_dev->dev, "bug: status.id 0x%x != INUSB_IBGTS_ID\n", status.id);
+       ni_usb_soft_update_status(board, status.ibsta, 0);
+       return 0;
+ }
+@@ -1091,7 +1072,7 @@ static void ni_usb_request_system_control(gpib_board_t *board, int request_contr
+       }
+       retval = ni_usb_write_registers(ni_priv, writes, i, &ibsta);
+       if (retval < 0) {
+-              dev_err(&usb_dev->dev, "%s: register write failed, retval=%i\n", __func__, retval);
++              dev_err(&usb_dev->dev, "register write failed, retval=%i\n", retval);
+               return; // retval;
+       }
+       if (!request_control)
+@@ -1117,10 +1098,8 @@ static void ni_usb_interface_clear(gpib_board_t *board, int assert)
+       if (assert == 0)
+               return;
+       out_data = kmalloc(out_data_length, GFP_KERNEL);
+-      if (!out_data)  {
+-              dev_err(&usb_dev->dev, "%s: kmalloc failed\n", __func__);
++      if (!out_data)
+               return;
+-      }
+       out_data[i++] = NIUSB_IBSIC_ID;
+       out_data[i++] = 0x0;
+       out_data[i++] = 0x0;
+@@ -1129,8 +1108,8 @@ static void ni_usb_interface_clear(gpib_board_t *board, int assert)
+       retval = ni_usb_send_bulk_msg(ni_priv, out_data, i, &bytes_written, 1000);
+       kfree(out_data);
+       if (retval || bytes_written != i) {
+-              dev_err(&usb_dev->dev, "%s: ni_usb_send_bulk_msg returned %i, bytes_written=%i, i=%i\n",
+-                      __func__, retval, bytes_written, i);
++              dev_err(&usb_dev->dev, "send_bulk_msg returned %i, bytes_written=%i, i=%i\n",
++                      retval, bytes_written, i);
+               return;
+       }
+       in_data = kmalloc(in_data_length, GFP_KERNEL);
+@@ -1139,8 +1118,8 @@ static void ni_usb_interface_clear(gpib_board_t *board, int assert)
+       retval = ni_usb_receive_bulk_msg(ni_priv, in_data, in_data_length, &bytes_read, 1000, 0);
+       if (retval || bytes_read != 12) {
+-              dev_err(&usb_dev->dev, "%s: ni_usb_receive_bulk_msg returned %i, bytes_read=%i\n",
+-                      __func__, retval, bytes_read);
++              dev_err(&usb_dev->dev, "receive_bulk_msg returned %i, bytes_read=%i\n",
++                      retval, bytes_read);
+               kfree(in_data);
+               return;
+       }
+@@ -1165,7 +1144,7 @@ static void ni_usb_remote_enable(gpib_board_t *board, int enable)
+               reg.value = AUX_CREN;
+       retval = ni_usb_write_registers(ni_priv, &reg, 1, &ibsta);
+       if (retval < 0) {
+-              dev_err(&usb_dev->dev, "%s: register write failed, retval=%i\n", __func__, retval);
++              dev_err(&usb_dev->dev, "register write failed, retval=%i\n", retval);
+               return; //retval;
+       }
+       ni_priv->ren_state = enable;
+@@ -1205,7 +1184,6 @@ static unsigned int ni_usb_update_status(gpib_board_t *board, unsigned int clear
+       u8 *buffer;
+       struct ni_usb_status_block status;
+-      //printk("%s: receive control pipe is %i\n", __func__, pipe);
+       buffer = kmalloc(buffer_length, GFP_KERNEL);
+       if (!buffer)
+               return board->status;
+@@ -1214,7 +1192,7 @@ static unsigned int ni_usb_update_status(gpib_board_t *board, unsigned int clear
+                                           USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+                                           0x200, 0x0, buffer, buffer_length, 1000);
+       if (retval != buffer_length) {
+-              dev_err(&usb_dev->dev, "%s: usb_control_msg returned %i\n", __func__, retval);
++              dev_err(&usb_dev->dev, "usb_control_msg returned %i\n", retval);
+               kfree(buffer);
+               return board->status;
+       }
+@@ -1233,7 +1211,6 @@ static void ni_usb_stop(struct ni_usb_priv *ni_priv)
+       u8 *buffer;
+       struct ni_usb_status_block status;
+-      //printk("%s: receive control pipe is %i\n", __func__, pipe);
+       buffer = kmalloc(buffer_length, GFP_KERNEL);
+       if (!buffer)
+               return;
+@@ -1242,7 +1219,7 @@ static void ni_usb_stop(struct ni_usb_priv *ni_priv)
+                                           USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+                                           0x0, 0x0, buffer, buffer_length, 1000);
+       if (retval != buffer_length) {
+-              dev_err(&usb_dev->dev, "%s: usb_control_msg returned %i\n", __func__, retval);
++              dev_err(&usb_dev->dev, "usb_control_msg returned %i\n", retval);
+               kfree(buffer);
+               return;
+       }
+@@ -1269,7 +1246,7 @@ static int ni_usb_primary_address(gpib_board_t *board, unsigned int address)
+       i++;
+       retval = ni_usb_write_registers(ni_priv, writes, i, &ibsta);
+       if (retval < 0) {
+-              dev_err(&usb_dev->dev, "%s: register write failed, retval=%i\n", __func__, retval);
++              dev_err(&usb_dev->dev, "register write failed, retval=%i\n", retval);
+               return retval;
+       }
+       ni_usb_soft_update_status(board, ibsta, 0);
+@@ -1317,7 +1294,7 @@ static int ni_usb_secondary_address(gpib_board_t *board, unsigned int address, i
+       i += ni_usb_write_sad(writes, address, enable);
+       retval = ni_usb_write_registers(ni_priv, writes, i, &ibsta);
+       if (retval < 0) {
+-              dev_err(&usb_dev->dev, "%s: register write failed, retval=%i\n", __func__, retval);
++              dev_err(&usb_dev->dev, "register write failed, retval=%i\n", retval);
+               return retval;
+       }
+       ni_usb_soft_update_status(board, ibsta, 0);
+@@ -1351,8 +1328,8 @@ static int ni_usb_parallel_poll(gpib_board_t *board, uint8_t *result)
+       kfree(out_data);
+       if (retval || bytes_written != i) {
+-              dev_err(&usb_dev->dev, "%s: ni_usb_send_bulk_msg returned %i, bytes_written=%i, i=%i\n",
+-                      __func__, retval, bytes_written, i);
++              dev_err(&usb_dev->dev, "send_bulk_msg returned %i, bytes_written=%i, i=%i\n",
++                      retval, bytes_written, i);
+               return retval;
+       }
+       in_data = kmalloc(in_data_length, GFP_KERNEL);
+@@ -1364,8 +1341,8 @@ static int ni_usb_parallel_poll(gpib_board_t *board, uint8_t *result)
+                                        &bytes_read, 1000, 1);
+       if (retval && retval != -ERESTARTSYS)   {
+-              dev_err(&usb_dev->dev, "%s: ni_usb_receive_bulk_msg returned %i, bytes_read=%i\n",
+-                      __func__, retval, bytes_read);
++              dev_err(&usb_dev->dev, "receive_bulk_msg returned %i, bytes_read=%i\n",
++                      retval, bytes_read);
+               kfree(in_data);
+               return retval;
+       }
+@@ -1391,7 +1368,7 @@ static void ni_usb_parallel_poll_configure(gpib_board_t *board, uint8_t config)
+       i++;
+       retval = ni_usb_write_registers(ni_priv, writes, i, &ibsta);
+       if (retval < 0) {
+-              dev_err(&usb_dev->dev, "%s: register write failed, retval=%i\n", __func__, retval);
++              dev_err(&usb_dev->dev, "register write failed, retval=%i\n", retval);
+               return;// retval;
+       }
+       ni_usb_soft_update_status(board, ibsta, 0);
+@@ -1416,7 +1393,7 @@ static void ni_usb_parallel_poll_response(gpib_board_t *board, int ist)
+       i++;
+       retval = ni_usb_write_registers(ni_priv, writes, i, &ibsta);
+       if (retval < 0) {
+-              dev_err(&usb_dev->dev, "%s: register write failed, retval=%i\n", __func__, retval);
++              dev_err(&usb_dev->dev, "register write failed, retval=%i\n", retval);
+               return;// retval;
+       }
+       ni_usb_soft_update_status(board, ibsta, 0);
+@@ -1438,7 +1415,7 @@ static void ni_usb_serial_poll_response(gpib_board_t *board, u8 status)
+       i++;
+       retval = ni_usb_write_registers(ni_priv, writes, i, &ibsta);
+       if (retval < 0) {
+-              dev_err(&usb_dev->dev, "%s: register write failed, retval=%i\n", __func__, retval);
++              dev_err(&usb_dev->dev, "register write failed, retval=%i\n", retval);
+               return;// retval;
+       }
+       ni_usb_soft_update_status(board, ibsta, 0);
+@@ -1465,7 +1442,7 @@ static void ni_usb_return_to_local(gpib_board_t *board)
+       i++;
+       retval = ni_usb_write_registers(ni_priv, writes, i, &ibsta);
+       if (retval < 0) {
+-              dev_err(&usb_dev->dev, "%s: register write failed, retval=%i\n", __func__, retval);
++              dev_err(&usb_dev->dev, "register write failed, retval=%i\n", retval);
+               return;// retval;
+       }
+       ni_usb_soft_update_status(board, ibsta, 0);
+@@ -1507,15 +1484,14 @@ static int ni_usb_line_status(const gpib_board_t *board)
+       if (retval || bytes_written != i) {
+               mutex_unlock(&ni_priv->addressed_transfer_lock);
+               if (retval != -EAGAIN)
+-                      dev_err(&usb_dev->dev, "%s: ni_usb_send_bulk_msg returned %i, bytes_written=%i, i=%i\n",
+-                              __func__, retval, bytes_written, i);
++                      dev_err(&usb_dev->dev, "send_bulk_msg returned %i, bytes_written=%i, i=%i\n",
++                              retval, bytes_written, i);
+               return retval;
+       }
+       in_data = kmalloc(in_data_length, GFP_KERNEL);
+       if (!in_data) {
+               mutex_unlock(&ni_priv->addressed_transfer_lock);
+-              dev_err(&usb_dev->dev, "%s: kmalloc failed\n", __func__);
+               return -ENOMEM;
+       }
+       retval = ni_usb_nonblocking_receive_bulk_msg(ni_priv, in_data, in_data_length,
+@@ -1525,8 +1501,8 @@ static int ni_usb_line_status(const gpib_board_t *board)
+       if (retval) {
+               if (retval != -EAGAIN)
+-                      dev_err(&usb_dev->dev, "%s: ni_usb_receive_bulk_msg returned %i, bytes_read=%i\n",
+-                              __func__, retval, bytes_read);
++                      dev_err(&usb_dev->dev, "receive_bulk_msg returned %i, bytes_read=%i\n",
++                              retval, bytes_read);
+               kfree(in_data);
+               return retval;
+       }
+@@ -1602,7 +1578,7 @@ static unsigned int ni_usb_t1_delay(gpib_board_t *board, unsigned int nano_sec)
+       i = ni_usb_setup_t1_delay(writes, nano_sec, &actual_ns);
+       retval = ni_usb_write_registers(ni_priv, writes, i, &ibsta);
+       if (retval < 0) {
+-              dev_err(&usb_dev->dev, "%s: register write failed, retval=%i\n", __func__, retval);
++              dev_err(&usb_dev->dev, "register write failed, retval=%i\n", retval);
+               return -1;      //FIXME should change return type to int for error reporting
+       }
+       board->t1_nano_sec = actual_ns;
+@@ -1734,7 +1710,7 @@ static int ni_usb_setup_init(gpib_board_t *board, struct ni_usb_register *writes
+       writes[i].value = AUX_CPPF;
+       i++;
+       if (i > NUM_INIT_WRITES) {
+-              dev_err(&usb_dev->dev, "%s: bug!, buffer overrun, i=%i\n", __func__, i);
++              dev_err(&usb_dev->dev, "bug!, buffer overrun, i=%i\n", i);
+               return 0;
+       }
+       return i;
+@@ -1760,7 +1736,7 @@ static int ni_usb_init(gpib_board_t *board)
+               return -EFAULT;
+       kfree(writes);
+       if (retval) {
+-              dev_err(&usb_dev->dev, "%s: register write failed, retval=%i\n", __func__, retval);
++              dev_err(&usb_dev->dev, "register write failed, retval=%i\n", retval);
+               return retval;
+       }
+       ni_usb_soft_update_status(board, ibsta, 0);
+@@ -1776,9 +1752,6 @@ static void ni_usb_interrupt_complete(struct urb *urb)
+       struct ni_usb_status_block status;
+       unsigned long flags;
+-//    printk("debug: %s: status=0x%x, error_count=%i, actual_length=%i\n", __func__,
+-//            urb->status, urb->error_count, urb->actual_length);
+-
+       switch (urb->status) {
+               /* success */
+       case 0:
+@@ -1791,23 +1764,21 @@ static void ni_usb_interrupt_complete(struct urb *urb)
+       default: /* other error, resubmit */
+               retval = usb_submit_urb(ni_priv->interrupt_urb, GFP_ATOMIC);
+               if (retval)
+-                      dev_err(&usb_dev->dev, "%s: failed to resubmit interrupt urb\n", __func__);
++                      dev_err(&usb_dev->dev, "failed to resubmit interrupt urb\n");
+               return;
+       }
+       ni_usb_parse_status_block(urb->transfer_buffer, &status);
+-//    printk("debug: ibsta=0x%x\n", status.ibsta);
+       spin_lock_irqsave(&board->spinlock, flags);
+       ni_priv->monitored_ibsta_bits &= ~status.ibsta;
+-//    printk("debug: monitored_ibsta_bits=0x%x\n", ni_priv->monitored_ibsta_bits);
+       spin_unlock_irqrestore(&board->spinlock, flags);
+       wake_up_interruptible(&board->wait);
+       retval = usb_submit_urb(ni_priv->interrupt_urb, GFP_ATOMIC);
+       if (retval)
+-              dev_err(&usb_dev->dev, "%s: failed to resubmit interrupt urb\n", __func__);
++              dev_err(&usb_dev->dev, "failed to resubmit interrupt urb\n");
+ }
+ static int ni_usb_set_interrupt_monitor(gpib_board_t *board, unsigned int monitored_bits)
+@@ -1819,22 +1790,20 @@ static int ni_usb_set_interrupt_monitor(gpib_board_t *board, unsigned int monito
+       u8 *buffer;
+       struct ni_usb_status_block status;
+       unsigned long flags;
+-      //printk("%s: receive control pipe is %i\n", __func__, pipe);
++
+       buffer = kmalloc(buffer_length, GFP_KERNEL);
+       if (!buffer)
+               return -ENOMEM;
+       spin_lock_irqsave(&board->spinlock, flags);
+       ni_priv->monitored_ibsta_bits = ni_usb_ibsta_monitor_mask & monitored_bits;
+-//    dev_err(&usb_dev->dev, "debug: %s: monitored_ibsta_bits=0x%x\n",
+-//    __func__, ni_priv->monitored_ibsta_bits);
+       spin_unlock_irqrestore(&board->spinlock, flags);
+       retval = ni_usb_receive_control_msg(ni_priv, NI_USB_WAIT_REQUEST, USB_DIR_IN |
+                                           USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+                                           0x300, ni_usb_ibsta_monitor_mask & monitored_bits,
+                                           buffer, buffer_length, 1000);
+       if (retval != buffer_length) {
+-              dev_err(&usb_dev->dev, "%s: usb_control_msg returned %i\n", __func__, retval);
++              dev_err(&usb_dev->dev, "usb_control_msg returned %i\n", retval);
+               kfree(buffer);
+               return -1;
+       }
+@@ -1870,8 +1839,7 @@ static int ni_usb_setup_urbs(gpib_board_t *board)
+       retval = usb_submit_urb(ni_priv->interrupt_urb, GFP_KERNEL);
+       mutex_unlock(&ni_priv->interrupt_transfer_lock);
+       if (retval) {
+-              dev_err(&usb_dev->dev, "%s: failed to submit first interrupt urb, retval=%i\n",
+-                      __func__, retval);
++              dev_err(&usb_dev->dev, "failed to submit first interrupt urb, retval=%i\n", retval);
+               return retval;
+       }
+       return 0;
+@@ -1902,7 +1870,6 @@ static int ni_usb_b_read_serial_number(struct ni_usb_priv *ni_priv)
+       int j;
+       unsigned int serial_number;
+-//    printk("%s: %s\n", __func__);
+       in_data = kmalloc(in_data_length, GFP_KERNEL);
+       if (!in_data)
+               return -ENOMEM;
+@@ -1922,20 +1889,19 @@ static int ni_usb_b_read_serial_number(struct ni_usb_priv *ni_priv)
+       i += ni_usb_bulk_termination(&out_data[i]);
+       retval = ni_usb_send_bulk_msg(ni_priv, out_data, out_data_length, &bytes_written, 1000);
+       if (retval) {
+-              dev_err(&usb_dev->dev, "%s: ni_usb_send_bulk_msg returned %i, bytes_written=%i, i=%li\n",
+-                      __func__,
++              dev_err(&usb_dev->dev, "send_bulk_msg returned %i, bytes_written=%i, i=%li\n",
+                       retval, bytes_written, (long)out_data_length);
+               goto serial_out;
+       }
+       retval = ni_usb_receive_bulk_msg(ni_priv, in_data, in_data_length, &bytes_read, 1000, 0);
+       if (retval) {
+-              dev_err(&usb_dev->dev, "%s: ni_usb_receive_bulk_msg returned %i, bytes_read=%i\n",
+-                      __func__, retval, bytes_read);
++              dev_err(&usb_dev->dev, "receive_bulk_msg returned %i, bytes_read=%i\n",
++                      retval, bytes_read);
+               ni_usb_dump_raw_block(in_data, bytes_read);
+               goto serial_out;
+       }
+       if (ARRAY_SIZE(results) < num_reads) {
+-              dev_err(&usb_dev->dev, "Setup bug\n");
++              dev_err(&usb_dev->dev, "serial number eetup bug\n");
+               retval = -EINVAL;
+               goto serial_out;
+       }
+@@ -1943,7 +1909,7 @@ static int ni_usb_b_read_serial_number(struct ni_usb_priv *ni_priv)
+       serial_number = 0;
+       for (j = 0; j < num_reads; ++j)
+               serial_number |= (results[j] & 0xff) << (8 * j);
+-      dev_info(&usb_dev->dev, "%s: board serial number is 0x%x\n", __func__, serial_number);
++      dev_dbg(&usb_dev->dev, "board serial number is 0x%x\n", serial_number);
+       retval = 0;
+ serial_out:
+       kfree(in_data);
+@@ -1971,22 +1937,22 @@ static int ni_usb_hs_wait_for_ready(struct ni_usb_priv *ni_priv)
+                                           USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+                                           0x0, 0x0, buffer, buffer_size, 1000);
+       if (retval < 0) {
+-              dev_err(&usb_dev->dev, "%s: usb_control_msg request 0x%x returned %i\n",
+-                      __func__, NI_USB_SERIAL_NUMBER_REQUEST, retval);
++              dev_err(&usb_dev->dev, "usb_control_msg request 0x%x returned %i\n",
++                      NI_USB_SERIAL_NUMBER_REQUEST, retval);
+               goto ready_out;
+       }
+       j = 0;
+       if (buffer[j] != NI_USB_SERIAL_NUMBER_REQUEST) {
+-              dev_err(&usb_dev->dev, "%s: unexpected data: buffer[%i]=0x%x, expected 0x%x\n",
+-                      __func__, j, (int)buffer[j], NI_USB_SERIAL_NUMBER_REQUEST);
++              dev_err(&usb_dev->dev, "unexpected data: buffer[%i]=0x%x, expected 0x%x\n",
++                      j, (int)buffer[j], NI_USB_SERIAL_NUMBER_REQUEST);
+               unexpected = 1;
+       }
+       if (unexpected)
+               ni_usb_dump_raw_block(buffer, retval);
+       // NI-USB-HS+ pads the serial with 0x0 to make 16 bytes
+       if (retval != 5 && retval != 16) {
+-              dev_err(&usb_dev->dev, "%s: received unexpected number of bytes = %i, expected 5 or 16\n",
+-                      __func__, retval);
++              dev_err(&usb_dev->dev, "received unexpected number of bytes = %i, expected 5 or 16\n",
++                      retval);
+               ni_usb_dump_raw_block(buffer, retval);
+       }
+       serial_number = 0;
+@@ -1994,7 +1960,7 @@ static int ni_usb_hs_wait_for_ready(struct ni_usb_priv *ni_priv)
+       serial_number |= (buffer[++j] << 8);
+       serial_number |= (buffer[++j] << 16);
+       serial_number |= (buffer[++j] << 24);
+-      dev_info(&usb_dev->dev, "%s: board serial number is 0x%x\n", __func__, serial_number);
++      dev_dbg(&usb_dev->dev, "board serial number is 0x%x\n", serial_number);
+       for (i = 0; i < timeout; ++i) {
+               int ready = 0;
+@@ -2002,26 +1968,26 @@ static int ni_usb_hs_wait_for_ready(struct ni_usb_priv *ni_priv)
+                                                   USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+                                                   0x0, 0x0, buffer, buffer_size, 100);
+               if (retval < 0) {
+-                      dev_err(&usb_dev->dev, "%s: usb_control_msg request 0x%x returned %i\n",
+-                              __func__, NI_USB_POLL_READY_REQUEST, retval);
++                      dev_err(&usb_dev->dev, "usb_control_msg request 0x%x returned %i\n",
++                              NI_USB_POLL_READY_REQUEST, retval);
+                       goto ready_out;
+               }
+               j = 0;
+               unexpected = 0;
+               if (buffer[j] != NI_USB_POLL_READY_REQUEST) { // [0]
+-                      dev_err(&usb_dev->dev, "%s: unexpected data: buffer[%i]=0x%x, expected 0x%x\n",
+-                              __func__, j, (int)buffer[j], NI_USB_POLL_READY_REQUEST);
++                      dev_err(&usb_dev->dev, "unexpected data: buffer[%i]=0x%x, expected 0x%x\n",
++                              j, (int)buffer[j], NI_USB_POLL_READY_REQUEST);
+                       unexpected = 1;
+               }
+               ++j;
+               if (buffer[j] != 0x1 && buffer[j] != 0x0) { // [1] HS+ sends 0x0
+-                      dev_err(&usb_dev->dev, "%s: unexpected data: buffer[%i]=0x%x, expected 0x1 or 0x0\n",
+-                              __func__, j, (int)buffer[j]);
++                      dev_err(&usb_dev->dev, "unexpected data: buffer[%i]=0x%x, expected 0x1 or 0x0\n",
++                              j, (int)buffer[j]);
+                       unexpected = 1;
+               }
+               if (buffer[++j] != 0x0) { // [2]
+-                      dev_err(&usb_dev->dev, "%s: unexpected data: buffer[%i]=0x%x, expected 0x%x\n",
+-                              __func__, j, (int)buffer[j], 0x0);
++                      dev_err(&usb_dev->dev, "unexpected data: buffer[%i]=0x%x, expected 0x%x\n",
++                              j, (int)buffer[j], 0x0);
+                       unexpected = 1;
+               }
+               ++j;
+@@ -2029,22 +1995,22 @@ static int ni_usb_hs_wait_for_ready(struct ni_usb_priv *ni_priv)
+               // NI-USB-HS+ sends 0x0
+               if (buffer[j] != 0x1 && buffer[j] != 0x8 && buffer[j] != 0x7 && buffer[j] != 0x0) {
+                       // [3]
+-                      dev_err(&usb_dev->dev, "%s: unexpected data: buffer[%i]=0x%x, expected 0x0, 0x1, 0x7 or 0x8\n",
+-                              __func__, j, (int)buffer[j]);
++                      dev_err(&usb_dev->dev, "unexpected data: buffer[%i]=0x%x, expected 0x0, 0x1, 0x7 or 0x8\n",
++                              j, (int)buffer[j]);
+                       unexpected = 1;
+               }
+               ++j;
+               // NI-USB-HS+ sends 0 here
+               if (buffer[j] != 0x30 && buffer[j] != 0x0) { // [4]
+-                      dev_err(&usb_dev->dev, "%s: unexpected data: buffer[%i]=0x%x, expected 0x0 or 0x30\n",
+-                              __func__, j, (int)buffer[j]);
++                      dev_err(&usb_dev->dev, "unexpected data: buffer[%i]=0x%x, expected 0x0 or 0x30\n",
++                              j, (int)buffer[j]);
+                       unexpected = 1;
+               }
+               ++j;
+               // MC usb-488 (and sometimes NI-USB-HS?) and NI-USB-HS+ sends 0x0 here
+               if (buffer[j] != 0x1 && buffer[j] != 0x0) { // [5]
+-                      dev_err(&usb_dev->dev, "%s: unexpected data: buffer[%i]=0x%x, expected 0x1 or 0x0\n",
+-                              __func__, j, (int)buffer[j]);
++                      dev_err(&usb_dev->dev, "unexpected data: buffer[%i]=0x%x, expected 0x1 or 0x0\n",
++                              j, (int)buffer[j]);
+                       unexpected = 1;
+               }
+               if (buffer[++j] != 0x0) { // [6]
+@@ -2052,8 +2018,8 @@ static int ni_usb_hs_wait_for_ready(struct ni_usb_priv *ni_priv)
+                       // NI-USB-HS+ sends 0xf here
+                       if (buffer[j] != 0x2 && buffer[j] != 0xe && buffer[j] != 0xf &&
+                           buffer[j] != 0x16)  {
+-                              dev_err(&usb_dev->dev, "%s: unexpected data: buffer[%i]=0x%x, expected 0x2, 0xe, 0xf or 0x16\n",
+-                                      __func__, j, (int)buffer[j]);
++                              dev_err(&usb_dev->dev, "unexpected data: buffer[%i]=0x%x, expected 0x2, 0xe, 0xf or 0x16\n",
++                                      j, (int)buffer[j]);
+                               unexpected = 1;
+                       }
+               }
+@@ -2062,30 +2028,30 @@ static int ni_usb_hs_wait_for_ready(struct ni_usb_priv *ni_priv)
+                       // MC usb-488 sends 0x5 here; MC usb-488A sends 0x6 here
+                       if (buffer[j] != 0x3 && buffer[j] != 0x5 && buffer[j] != 0x6 &&
+                           buffer[j] != 0x8)   {
+-                              dev_err(&usb_dev->dev, "%s: unexpected data: buffer[%i]=0x%x, expected 0x3 or 0x5, 0x6 or 0x08\n",
+-                                      __func__, j, (int)buffer[j]);
++                              dev_err(&usb_dev->dev, "unexpected data: buffer[%i]=0x%x, expected 0x3 or 0x5, 0x6 or 0x08\n",
++                                      j, (int)buffer[j]);
+                               unexpected = 1;
+                       }
+               }
+               ++j;
+               if (buffer[j] != 0x0 && buffer[j] != 0x2) { // [8] MC usb-488 sends 0x2 here
+-                      dev_err(&usb_dev->dev, "%s: unexpected data: buffer[%i]=0x%x, expected 0x0 or 0x2\n",
+-                              __func__, j, (int)buffer[j]);
++                      dev_err(&usb_dev->dev, " unexpected data: buffer[%i]=0x%x, expected 0x0 or 0x2\n",
++                              j, (int)buffer[j]);
+                       unexpected = 1;
+               }
+               ++j;
+               // MC usb-488A and NI-USB-HS sends 0x3 here; NI-USB-HS+ sends 0x30 here
+               if (buffer[j] != 0x0 && buffer[j] != 0x3 && buffer[j] != 0x30) { // [9]
+-                      dev_err(&usb_dev->dev, "%s: unexpected data: buffer[%i]=0x%x, expected 0x0, 0x3 or 0x30\n",
+-                              __func__, j, (int)buffer[j]);
++                      dev_err(&usb_dev->dev, "unexpected data: buffer[%i]=0x%x, expected 0x0, 0x3 or 0x30\n",
++                              j, (int)buffer[j]);
+                       unexpected = 1;
+               }
+               if (buffer[++j] != 0x0) {
+                       ready = 1;
+                       if (buffer[j] != 0x96 && buffer[j] != 0x7 && buffer[j] != 0x6e) {
+ // [10] MC usb-488 sends 0x7 here
+-                              dev_err(&usb_dev->dev, "%s: unexpected data: buffer[%i]=0x%x, expected 0x96, 0x07 or 0x6e\n",
+-                                      __func__, j, (int)buffer[j]);
++                              dev_err(&usb_dev->dev, "unexpected data: buffer[%i]=0x%x, expected 0x96, 0x07 or 0x6e\n",
++                                      j, (int)buffer[j]);
+                               unexpected = 1;
+                       }
+               }
+@@ -2095,7 +2061,6 @@ static int ni_usb_hs_wait_for_ready(struct ni_usb_priv *ni_priv)
+                       break;
+               retval = msleep_interruptible(msec_sleep_duration);
+               if (retval) {
+-                      dev_err(&usb_dev->dev, "ni_usb_gpib: msleep interrupted\n");
+                       retval = -ERESTARTSYS;
+                       goto ready_out;
+               }
+@@ -2104,7 +2069,7 @@ static int ni_usb_hs_wait_for_ready(struct ni_usb_priv *ni_priv)
+ ready_out:
+       kfree(buffer);
+-      dev_dbg(&usb_dev->dev, "%s: exit retval=%d\n", __func__, retval);
++      dev_dbg(&usb_dev->dev, "exit retval=%d\n", retval);
+       return retval;
+ }
+@@ -2132,14 +2097,14 @@ static int ni_usb_hs_plus_extra_init(struct ni_usb_priv *ni_priv)
+                                                   USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+                                                   0x0, 0x0, buffer, transfer_size, 1000);
+               if (retval < 0) {
+-                      dev_err(&usb_dev->dev, "%s: usb_control_msg request 0x%x returned %i\n",
+-                              __func__, NI_USB_HS_PLUS_0x48_REQUEST, retval);
++                      dev_err(&usb_dev->dev, "usb_control_msg request 0x%x returned %i\n",
++                              NI_USB_HS_PLUS_0x48_REQUEST, retval);
+                       break;
+               }
+               // expected response data: 48 f3 30 00 00 00 00 00 00 00 00 00 00 00 00 00
+               if (buffer[0] != NI_USB_HS_PLUS_0x48_REQUEST)
+-                      dev_err(&usb_dev->dev, "%s: unexpected data: buffer[0]=0x%x, expected 0x%x\n",
+-                              __func__, (int)buffer[0], NI_USB_HS_PLUS_0x48_REQUEST);
++                      dev_err(&usb_dev->dev, "unexpected data: buffer[0]=0x%x, expected 0x%x\n",
++                              (int)buffer[0], NI_USB_HS_PLUS_0x48_REQUEST);
+               transfer_size = 2;
+@@ -2147,14 +2112,14 @@ static int ni_usb_hs_plus_extra_init(struct ni_usb_priv *ni_priv)
+                                                   USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+                                                   0x1, 0x0, buffer, transfer_size, 1000);
+               if (retval < 0) {
+-                      dev_err(&usb_dev->dev, "%s: usb_control_msg request 0x%x returned %i\n",
+-                              __func__, NI_USB_HS_PLUS_LED_REQUEST, retval);
++                      dev_err(&usb_dev->dev, "usb_control_msg request 0x%x returned %i\n",
++                              NI_USB_HS_PLUS_LED_REQUEST, retval);
+                       break;
+               }
+               // expected response data: 4b 00
+               if (buffer[0] != NI_USB_HS_PLUS_LED_REQUEST)
+-                      dev_err(&usb_dev->dev, "%s: unexpected data: buffer[0]=0x%x, expected 0x%x\n",
+-                              __func__, (int)buffer[0], NI_USB_HS_PLUS_LED_REQUEST);
++                      dev_err(&usb_dev->dev, "unexpected data: buffer[0]=0x%x, expected 0x%x\n",
++                              (int)buffer[0], NI_USB_HS_PLUS_LED_REQUEST);
+               transfer_size = 9;
+@@ -2163,15 +2128,14 @@ static int ni_usb_hs_plus_extra_init(struct ni_usb_priv *ni_priv)
+                                                   USB_RECIP_INTERFACE,
+                                                   0x0, 0x1, buffer, transfer_size, 1000);
+               if (retval < 0) {
+-                      dev_err(&usb_dev->dev, "%s: usb_control_msg request 0x%x returned %i\n",
+-                              __func__, NI_USB_HS_PLUS_0xf8_REQUEST, retval);
++                      dev_err(&usb_dev->dev, "usb_control_msg request 0x%x returned %i\n",
++                              NI_USB_HS_PLUS_0xf8_REQUEST, retval);
+                       break;
+               }
+               // expected response data: f8 01 00 00 00 01 00 00 00
+               if (buffer[0] != NI_USB_HS_PLUS_0xf8_REQUEST)
+-                      dev_err(&usb_dev->dev, "%s: unexpected data: buffer[0]=0x%x, expected 0x%x\n",
+-                              __func__, (int)buffer[0], NI_USB_HS_PLUS_0xf8_REQUEST);
+-
++                      dev_err(&usb_dev->dev, "unexpected data: buffer[0]=0x%x, expected 0x%x\n",
++                              (int)buffer[0], NI_USB_HS_PLUS_0xf8_REQUEST);
+       } while (0);
+       // cleanup
+@@ -2190,7 +2154,7 @@ static inline int ni_usb_device_match(struct usb_interface *interface,
+ static int ni_usb_attach(gpib_board_t *board, const gpib_board_config_t *config)
+ {
+       int retval;
+-      int i;
++      int i, index;
+       struct ni_usb_priv *ni_priv;
+       int product_id;
+       struct usb_device *usb_dev;
+@@ -2209,19 +2173,17 @@ static int ni_usb_attach(gpib_board_t *board, const gpib_board_config_t *config)
+                       ni_priv->bus_interface = ni_usb_driver_interfaces[i];
+                       usb_set_intfdata(ni_usb_driver_interfaces[i], board);
+                       usb_dev = interface_to_usbdev(ni_priv->bus_interface);
+-                      dev_info(&usb_dev->dev,
+-                               "bus %d dev num %d attached to gpib minor %d, NI usb interface %i\n",
+-                               usb_dev->bus->busnum, usb_dev->devnum, board->minor, i);
++                      index = i;
+                       break;
+               }
+       }
+       if (i == MAX_NUM_NI_USB_INTERFACES) {
+               mutex_unlock(&ni_usb_hotplug_lock);
+-              pr_err("No supported NI usb gpib adapters found, have you loaded its firmware?\n");
++              dev_err(board->gpib_dev, "No supported adapters found, have you loaded its firmware?\n");
+               return -ENODEV;
+       }
+       if (usb_reset_configuration(interface_to_usbdev(ni_priv->bus_interface)))
+-              dev_err(&usb_dev->dev, "ni_usb_gpib: usb_reset_configuration() failed.\n");
++              dev_err(&usb_dev->dev, "usb_reset_configuration() failed.\n");
+       product_id = le16_to_cpu(usb_dev->descriptor.idProduct);
+       ni_priv->product_id = product_id;
+@@ -2294,7 +2256,9 @@ static int ni_usb_attach(gpib_board_t *board, const gpib_board_config_t *config)
+       }
+       mutex_unlock(&ni_usb_hotplug_lock);
+-      dev_info(&usb_dev->dev, "%s: attached\n", __func__);
++      dev_info(&usb_dev->dev,
++               "bus %d dev num %d attached to gpib%d, intf %i\n",
++               usb_dev->bus->busnum, usb_dev->devnum, board->minor, index);
+       return retval;
+ }
+@@ -2302,27 +2266,19 @@ static int ni_usb_shutdown_hardware(struct ni_usb_priv *ni_priv)
+ {
+       struct usb_device *usb_dev = interface_to_usbdev(ni_priv->bus_interface);
+       int retval;
+-      int i = 0;
+       struct ni_usb_register writes[2];
+       static const int writes_length = ARRAY_SIZE(writes);
+       unsigned int ibsta;
+-//    printk("%s: %s\n", __func__);
+-      writes[i].device = NIUSB_SUBDEV_TNT4882;
+-      writes[i].address = nec7210_to_tnt4882_offset(AUXMR);
+-      writes[i].value = AUX_CR;
+-      i++;
+-      writes[i].device = NIUSB_SUBDEV_UNKNOWN3;
+-      writes[i].address = 0x10;
+-      writes[i].value = 0x0;
+-      i++;
+-      if (i > writes_length) {
+-              dev_err(&usb_dev->dev, "%s: bug!, buffer overrun, i=%i\n", __func__, i);
+-              return -EINVAL;
+-      }
+-      retval = ni_usb_write_registers(ni_priv, writes, i, &ibsta);
++      writes[0].device = NIUSB_SUBDEV_TNT4882;
++      writes[0].address = nec7210_to_tnt4882_offset(AUXMR);
++      writes[0].value = AUX_CR;
++      writes[1].device = NIUSB_SUBDEV_UNKNOWN3;
++      writes[1].address = 0x10;
++      writes[1].value = 0x0;
++      retval = ni_usb_write_registers(ni_priv, writes, writes_length, &ibsta);
+       if (retval) {
+-              dev_err(&usb_dev->dev, "%s: register write failed, retval=%i\n", __func__, retval);
++              dev_err(&usb_dev->dev, "register write failed, retval=%i\n", retval);
+               return retval;
+       }
+       return 0;
+@@ -2411,7 +2367,7 @@ static int ni_usb_driver_probe(struct usb_interface *interface,  const struct usb
+       if (i == MAX_NUM_NI_USB_INTERFACES) {
+               usb_put_dev(usb_dev);
+               mutex_unlock(&ni_usb_hotplug_lock);
+-              dev_err(&usb_dev->dev, "%s: ni_usb_driver_interfaces[] full\n", __func__);
++              dev_err(&usb_dev->dev, "ni_usb_driver_interfaces[] full\n");
+               return -1;
+       }
+       path = kmalloc(path_length, GFP_KERNEL);
+@@ -2421,7 +2377,7 @@ static int ni_usb_driver_probe(struct usb_interface *interface,  const struct usb
+               return -ENOMEM;
+       }
+       usb_make_path(usb_dev, path, path_length);
+-      dev_info(&usb_dev->dev, "ni_usb_gpib: probe succeeded for path: %s\n", path);
++      dev_info(&usb_dev->dev, "probe succeeded for path: %s\n", path);
+       kfree(path);
+       mutex_unlock(&ni_usb_hotplug_lock);
+       return 0;
+@@ -2456,8 +2412,7 @@ static void ni_usb_driver_disconnect(struct usb_interface *interface)
+               }
+       }
+       if (i == MAX_NUM_NI_USB_INTERFACES)
+-              dev_err(&usb_dev->dev, "%s: unable to find interface in ni_usb_driver_interfaces[]? bug?\n",
+-                      __func__);
++              dev_err(&usb_dev->dev, "unable to find interface  bug?\n");
+       usb_put_dev(usb_dev);
+       mutex_unlock(&ni_usb_hotplug_lock);
+ }
+@@ -2496,9 +2451,9 @@ static int ni_usb_driver_suspend(struct usb_interface *interface, pm_message_t m
+                       ni_usb_cleanup_urbs(ni_priv);
+                       mutex_unlock(&ni_priv->interrupt_transfer_lock);
+               }
+-              dev_info(&usb_dev->dev,
+-                       "bus %d dev num %d  gpib minor %d, ni usb interface %i suspended\n",
+-                       usb_dev->bus->busnum, usb_dev->devnum, board->minor, i);
++              dev_dbg(&usb_dev->dev,
++                      "bus %d dev num %d gpib%d, interface %i suspended\n",
++                      usb_dev->bus->busnum, usb_dev->devnum, board->minor, i);
+       }
+       mutex_unlock(&ni_usb_hotplug_lock);
+@@ -2533,15 +2488,15 @@ static int ni_usb_driver_resume(struct usb_interface *interface)
+                       mutex_lock(&ni_priv->interrupt_transfer_lock);
+                       retval = usb_submit_urb(ni_priv->interrupt_urb, GFP_KERNEL);
+                       if (retval) {
+-                              dev_err(&usb_dev->dev, "%s: failed to resubmit interrupt urb, retval=%i\n",
+-                                      __func__, retval);
++                              dev_err(&usb_dev->dev, "resume failed to resubmit interrupt urb, retval=%i\n",
++                                      retval);
+                               mutex_unlock(&ni_priv->interrupt_transfer_lock);
+                               mutex_unlock(&ni_usb_hotplug_lock);
+                               return retval;
+                       }
+                       mutex_unlock(&ni_priv->interrupt_transfer_lock);
+               } else {
+-                      dev_err(&usb_dev->dev, "%s: bug! int urb not set up\n", __func__);
++                      dev_err(&usb_dev->dev, "bug! resume int urb not set up\n");
+                       mutex_unlock(&ni_usb_hotplug_lock);
+                       return -EINVAL;
+               }
+@@ -2598,9 +2553,9 @@ static int ni_usb_driver_resume(struct usb_interface *interface)
+               if (ni_priv->ren_state)
+                       ni_usb_remote_enable(board, 1);
+-              dev_info(&usb_dev->dev,
+-                       "bus %d dev num %d  gpib minor %d, ni usb interface %i resumed\n",
+-                       usb_dev->bus->busnum, usb_dev->devnum, board->minor, i);
++              dev_dbg(&usb_dev->dev,
++                      "bus %d dev num %d gpib%d, interface %i resumed\n",
++                      usb_dev->bus->busnum, usb_dev->devnum, board->minor, i);
+       }
+       mutex_unlock(&ni_usb_hotplug_lock);
+@@ -2608,7 +2563,7 @@ static int ni_usb_driver_resume(struct usb_interface *interface)
+ }
+ static struct usb_driver ni_usb_bus_driver = {
+-      .name = "ni_usb_gpib",
++      .name = DRV_NAME,
+       .probe = ni_usb_driver_probe,
+       .disconnect = ni_usb_driver_disconnect,
+       .suspend = ni_usb_driver_suspend,
+@@ -2621,19 +2576,18 @@ static int __init ni_usb_init_module(void)
+       int i;
+       int ret;
+-      pr_info("ni_usb_gpib driver loading\n");
+       for (i = 0; i < MAX_NUM_NI_USB_INTERFACES; i++)
+               ni_usb_driver_interfaces[i] = NULL;
+       ret = usb_register(&ni_usb_bus_driver);
+       if (ret) {
+-              pr_err("ni_usb_gpib: usb_register failed: error = %d\n", ret);
++              pr_err("usb_register failed: error = %d\n", ret);
+               return ret;
+       }
+       ret = gpib_register_driver(&ni_usb_gpib_interface, THIS_MODULE);
+       if (ret) {
+-              pr_err("ni_usb_gpib: gpib_register_driver failed: error = %d\n", ret);
++              pr_err("gpib_register_driver failed: error = %d\n", ret);
+               return ret;
+       }
+@@ -2642,7 +2596,6 @@ static int __init ni_usb_init_module(void)
+ static void __exit ni_usb_exit_module(void)
+ {
+-      pr_info("ni_usb_gpib driver unloading\n");
+       gpib_unregister_driver(&ni_usb_gpib_interface);
+       usb_deregister(&ni_usb_bus_driver);
+ }
+-- 
+2.39.5
+
diff --git a/queue-6.13/staging-gpib-ni_usb-handle-gpib_register_driver-erro.patch b/queue-6.13/staging-gpib-ni_usb-handle-gpib_register_driver-erro.patch
new file mode 100644 (file)
index 0000000..20ea4c6
--- /dev/null
@@ -0,0 +1,60 @@
+From 2814c78b7f141146634dc36067e8db4101a0d90d Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Tue, 31 Dec 2024 00:26:33 +0530
+Subject: staging: gpib: ni_usb: Handle gpib_register_driver() errors
+
+From: Nihar Chaithanya <niharchaithanya@gmail.com>
+
+[ Upstream commit 635ddb8ccdbde0d917b0a7448b0fd9d6cc27a2a9 ]
+
+The usb_register() function can fail and returns an error value which
+is not returned. The function gpib_register_driver() can also fail
+which can result in semi-registered module.
+
+In case gpib_register_driver() fails unregister the previous usb driver
+registering function. Return the error value if gpib_register_driver()
+or usb_register() functions fail. Add pr_err() statements indicating the
+fail and error value.
+
+Signed-off-by: Nihar Chaithanya <niharchaithanya@gmail.com>
+Link: https://lore.kernel.org/r/20241230185633.175690-14-niharchaithanya@gmail.com
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Stable-dep-of: a239c6e91b66 ("staging: gpib: Fix Oops after disconnect in ni_usb")
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ drivers/staging/gpib/ni_usb/ni_usb_gpib.c | 15 +++++++++++++--
+ 1 file changed, 13 insertions(+), 2 deletions(-)
+
+diff --git a/drivers/staging/gpib/ni_usb/ni_usb_gpib.c b/drivers/staging/gpib/ni_usb/ni_usb_gpib.c
+index 70b8b305e13b6..3c4132fd6de95 100644
+--- a/drivers/staging/gpib/ni_usb/ni_usb_gpib.c
++++ b/drivers/staging/gpib/ni_usb/ni_usb_gpib.c
+@@ -2619,12 +2619,23 @@ static struct usb_driver ni_usb_bus_driver = {
+ static int __init ni_usb_init_module(void)
+ {
+       int i;
++      int ret;
+       pr_info("ni_usb_gpib driver loading\n");
+       for (i = 0; i < MAX_NUM_NI_USB_INTERFACES; i++)
+               ni_usb_driver_interfaces[i] = NULL;
+-      usb_register(&ni_usb_bus_driver);
+-      gpib_register_driver(&ni_usb_gpib_interface, THIS_MODULE);
++
++      ret = usb_register(&ni_usb_bus_driver);
++      if (ret) {
++              pr_err("ni_usb_gpib: usb_register failed: error = %d\n", ret);
++              return ret;
++      }
++
++      ret = gpib_register_driver(&ni_usb_gpib_interface, THIS_MODULE);
++      if (ret) {
++              pr_err("ni_usb_gpib: gpib_register_driver failed: error = %d\n", ret);
++              return ret;
++      }
+       return 0;
+ }
+-- 
+2.39.5
+
diff --git a/queue-6.13/staging-gpib-replace-semaphore-with-completion-for-o.patch b/queue-6.13/staging-gpib-replace-semaphore-with-completion-for-o.patch
new file mode 100644 (file)
index 0000000..424a051
--- /dev/null
@@ -0,0 +1,114 @@
+From 6c58ca9035bdf58e348e646b48a495593cbfd4b3 Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Thu, 12 Dec 2024 21:51:04 +0530
+Subject: staging: gpib: Replace semaphore with completion for one-time
+ signaling
+
+From: Santosh Mahto <eisantosh95@gmail.com>
+
+[ Upstream commit 5d4db9cf4135d82634c7f31aac73081fba3a356e ]
+
+Replaced 'down_interruptible()' and 'up()' calls
+with 'wait_for_completion_interruptible()' and
+'complete()' respectively. The completion API
+simplifies the code and adheres to kernel best
+practices for synchronization primitive
+
+Signed-off-by: Santosh Mahto <eisantosh95@gmail.com>
+Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>
+Link: https://lore.kernel.org/r/20241212162112.13083-1-eisantosh95@gmail.com
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Stable-dep-of: a239c6e91b66 ("staging: gpib: Fix Oops after disconnect in ni_usb")
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ drivers/staging/gpib/ni_usb/ni_usb_gpib.c | 16 ++++++++--------
+ drivers/staging/gpib/ni_usb/ni_usb_gpib.h |  2 +-
+ 2 files changed, 9 insertions(+), 9 deletions(-)
+
+diff --git a/drivers/staging/gpib/ni_usb/ni_usb_gpib.c b/drivers/staging/gpib/ni_usb/ni_usb_gpib.c
+index b7b6fb1be3790..70b8b305e13b6 100644
+--- a/drivers/staging/gpib/ni_usb/ni_usb_gpib.c
++++ b/drivers/staging/gpib/ni_usb/ni_usb_gpib.c
+@@ -85,7 +85,7 @@ static void ni_usb_bulk_complete(struct urb *urb)
+ //    printk("debug: %s: status=0x%x, error_count=%i, actual_length=%i\n",  __func__,
+ //            urb->status, urb->error_count, urb->actual_length);
+-      up(&context->complete);
++      complete(&context->complete);
+ }
+ static void ni_usb_timeout_handler(struct timer_list *t)
+@@ -94,7 +94,7 @@ static void ni_usb_timeout_handler(struct timer_list *t)
+       struct ni_usb_urb_ctx *context = &ni_priv->context;
+       context->timed_out = 1;
+-      up(&context->complete);
++      complete(&context->complete);
+ };
+ // I'm using nonblocking loosely here, it only means -EAGAIN can be returned in certain cases
+@@ -124,7 +124,7 @@ static int ni_usb_nonblocking_send_bulk_msg(struct ni_usb_priv *ni_priv, void *d
+       }
+       usb_dev = interface_to_usbdev(ni_priv->bus_interface);
+       out_pipe = usb_sndbulkpipe(usb_dev, ni_priv->bulk_out_endpoint);
+-      sema_init(&context->complete, 0);
++      init_completion(&context->complete);
+       context->timed_out = 0;
+       usb_fill_bulk_urb(ni_priv->bulk_urb, usb_dev, out_pipe, data, data_length,
+                         &ni_usb_bulk_complete, context);
+@@ -143,7 +143,7 @@ static int ni_usb_nonblocking_send_bulk_msg(struct ni_usb_priv *ni_priv, void *d
+               return retval;
+       }
+       mutex_unlock(&ni_priv->bulk_transfer_lock);
+-      down(&context->complete);    // wait for ni_usb_bulk_complete
++      wait_for_completion(&context->complete);    // wait for ni_usb_bulk_complete
+       if (context->timed_out) {
+               usb_kill_urb(ni_priv->bulk_urb);
+               dev_err(&usb_dev->dev, "%s: killed urb due to timeout\n", __func__);
+@@ -210,7 +210,7 @@ static int ni_usb_nonblocking_receive_bulk_msg(struct ni_usb_priv *ni_priv,
+       }
+       usb_dev = interface_to_usbdev(ni_priv->bus_interface);
+       in_pipe = usb_rcvbulkpipe(usb_dev, ni_priv->bulk_in_endpoint);
+-      sema_init(&context->complete, 0);
++      init_completion(&context->complete);
+       context->timed_out = 0;
+       usb_fill_bulk_urb(ni_priv->bulk_urb, usb_dev, in_pipe, data, data_length,
+                         &ni_usb_bulk_complete, context);
+@@ -231,7 +231,7 @@ static int ni_usb_nonblocking_receive_bulk_msg(struct ni_usb_priv *ni_priv,
+       }
+       mutex_unlock(&ni_priv->bulk_transfer_lock);
+       if (interruptible) {
+-              if (down_interruptible(&context->complete)) {
++              if (wait_for_completion_interruptible(&context->complete)) {
+                       /* If we got interrupted by a signal while
+                        * waiting for the usb gpib to respond, we
+                        * should send a stop command so it will
+@@ -243,10 +243,10 @@ static int ni_usb_nonblocking_receive_bulk_msg(struct ni_usb_priv *ni_priv,
+                       /* now do an uninterruptible wait, it shouldn't take long
+                        *      for the board to respond now.
+                        */
+-                      down(&context->complete);
++                      wait_for_completion(&context->complete);
+               }
+       } else {
+-              down(&context->complete);
++              wait_for_completion(&context->complete);
+       }
+       if (context->timed_out) {
+               usb_kill_urb(ni_priv->bulk_urb);
+diff --git a/drivers/staging/gpib/ni_usb/ni_usb_gpib.h b/drivers/staging/gpib/ni_usb/ni_usb_gpib.h
+index 9b21dfa0f3f6d..4b297db09a9bf 100644
+--- a/drivers/staging/gpib/ni_usb/ni_usb_gpib.h
++++ b/drivers/staging/gpib/ni_usb/ni_usb_gpib.h
+@@ -56,7 +56,7 @@ enum hs_plus_endpoint_addresses {
+ };
+ struct ni_usb_urb_ctx {
+-      struct semaphore complete;
++      struct completion complete;
+       unsigned timed_out : 1;
+ };
+-- 
+2.39.5
+
diff --git a/queue-6.13/tools-power-turbostat-report-corethr-per-measurement.patch b/queue-6.13/tools-power-turbostat-report-corethr-per-measurement.patch
new file mode 100644 (file)
index 0000000..b71b701
--- /dev/null
@@ -0,0 +1,59 @@
+From 860a95fd4a2f09eb02c9a79e8839c5e933ebf06c Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Sun, 6 Apr 2025 11:18:39 -0400
+Subject: tools/power turbostat: report CoreThr per measurement interval
+
+From: Len Brown <len.brown@intel.com>
+
+[ Upstream commit f729775f79a9c942c6c82ed6b44bd030afe10423 ]
+
+The CoreThr column displays total thermal throttling events
+since boot time.
+
+Change it to report events during the measurement interval.
+
+This is more useful for showing a user the current conditions.
+Total events since boot time are still available to the user via
+/sys/devices/system/cpu/cpu*/thermal_throttle/*
+
+Document CoreThr on turbostat.8
+
+Fixes: eae97e053fe30 ("turbostat: Support thermal throttle count print")
+Reported-by: Arjan van de Ven <arjan@linux.intel.com>
+Signed-off-by: Len Brown <len.brown@intel.com>
+Cc: Chen Yu <yu.c.chen@intel.com>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ tools/power/x86/turbostat/turbostat.8 | 2 ++
+ tools/power/x86/turbostat/turbostat.c | 2 +-
+ 2 files changed, 3 insertions(+), 1 deletion(-)
+
+diff --git a/tools/power/x86/turbostat/turbostat.8 b/tools/power/x86/turbostat/turbostat.8
+index a7f7ed01421c1..172191f841cd4 100644
+--- a/tools/power/x86/turbostat/turbostat.8
++++ b/tools/power/x86/turbostat/turbostat.8
+@@ -168,6 +168,8 @@ The system configuration dump (if --quiet is not used) is followed by statistics
+ .PP
+ \fBPkgTmp\fP Degrees Celsius reported by the per-package Package Thermal Monitor.
+ .PP
++\fBCoreThr\fP Core Thermal Throttling events during the measurement interval.  Note that events since boot can be find in /sys/devices/system/cpu/cpu*/thermal_throttle/*
++.PP
+ \fBGFX%rc6\fP The percentage of time the GPU is in the "render C6" state, rc6, during the measurement interval. From /sys/class/drm/card0/power/rc6_residency_ms or /sys/class/drm/card0/gt/gt0/rc6_residency_ms or /sys/class/drm/card0/device/tile0/gtN/gtidle/idle_residency_ms depending on the graphics driver being used.
+ .PP
+ \fBGFXMHz\fP Instantaneous snapshot of what sysfs presents at the end of the measurement interval. From /sys/class/graphics/fb0/device/drm/card0/gt_cur_freq_mhz or /sys/class/drm/card0/gt_cur_freq_mhz or /sys/class/drm/card0/gt/gt0/rps_cur_freq_mhz or /sys/class/drm/card0/device/tile0/gtN/freq0/cur_freq depending on the graphics driver being used.
+diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
+index 8ec677c639ece..08b1069d9ab54 100644
+--- a/tools/power/x86/turbostat/turbostat.c
++++ b/tools/power/x86/turbostat/turbostat.c
+@@ -3298,7 +3298,7 @@ void delta_core(struct core_data *new, struct core_data *old)
+       old->c6 = new->c6 - old->c6;
+       old->c7 = new->c7 - old->c7;
+       old->core_temp_c = new->core_temp_c;
+-      old->core_throt_cnt = new->core_throt_cnt;
++      old->core_throt_cnt = new->core_throt_cnt - old->core_throt_cnt;
+       old->mc6_us = new->mc6_us - old->mc6_us;
+       DELTA_WRAP32(new->core_energy.raw_value, old->core_energy.raw_value);
+-- 
+2.39.5
+
diff --git a/queue-6.13/tools-power-turbostat-restore-gfx-sysfs-fflush-call.patch b/queue-6.13/tools-power-turbostat-restore-gfx-sysfs-fflush-call.patch
new file mode 100644 (file)
index 0000000..96b0c0c
--- /dev/null
@@ -0,0 +1,35 @@
+From 0fd2148888abcfe30c587a4c3285a0b2e796d444 Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Wed, 19 Mar 2025 08:53:07 +0800
+Subject: tools/power turbostat: Restore GFX sysfs fflush() call
+
+From: Zhang Rui <rui.zhang@intel.com>
+
+[ Upstream commit f8b136ef2605c1bf62020462d10e35228760aa19 ]
+
+Do fflush() to discard the buffered data, before each read of the
+graphics sysfs knobs.
+
+Fixes: ba99a4fc8c24 ("tools/power turbostat: Remove unnecessary fflush() call")
+Signed-off-by: Zhang Rui <rui.zhang@intel.com>
+Signed-off-by: Len Brown <len.brown@intel.com>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ tools/power/x86/turbostat/turbostat.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
+index 08b1069d9ab54..634fb287716ab 100644
+--- a/tools/power/x86/turbostat/turbostat.c
++++ b/tools/power/x86/turbostat/turbostat.c
+@@ -5836,6 +5836,7 @@ int snapshot_graphics(int idx)
+       int retval;
+       rewind(gfx_info[idx].fp);
++      fflush(gfx_info[idx].fp);
+       switch (idx) {
+       case GFX_rc6:
+-- 
+2.39.5
+
diff --git a/queue-6.13/tracing-correct-the-refcount-if-the-hist-hist_debug-.patch b/queue-6.13/tracing-correct-the-refcount-if-the-hist-hist_debug-.patch
new file mode 100644 (file)
index 0000000..4655860
--- /dev/null
@@ -0,0 +1,92 @@
+From 112d8fc6ce16d424cd0cebe42f62dcafe595321c Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Fri, 14 Mar 2025 06:53:35 +0000
+Subject: tracing: Correct the refcount if the hist/hist_debug file fails to
+ open
+
+From: Tengda Wu <wutengda@huaweicloud.com>
+
+[ Upstream commit 0b4ffbe4888a2c71185eaf5c1a02dd3586a9bc04 ]
+
+The function event_{hist,hist_debug}_open() maintains the refcount of
+'file->tr' and 'file' through tracing_open_file_tr(). However, it does
+not roll back these counts on subsequent failure paths, resulting in a
+refcount leak.
+
+A very obvious case is that if the hist/hist_debug file belongs to a
+specific instance, the refcount leak will prevent the deletion of that
+instance, as it relies on the condition 'tr->ref == 1' within
+__remove_instance().
+
+Fix this by calling tracing_release_file_tr() on all failure paths in
+event_{hist,hist_debug}_open() to correct the refcount.
+
+Cc: stable@vger.kernel.org
+Cc: Masami Hiramatsu <mhiramat@kernel.org>
+Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+Cc: Zheng Yejian <zhengyejian1@huawei.com>
+Link: https://lore.kernel.org/20250314065335.1202817-1-wutengda@huaweicloud.com
+Fixes: 1cc111b9cddc ("tracing: Fix uaf issue when open the hist or hist_debug file")
+Signed-off-by: Tengda Wu <wutengda@huaweicloud.com>
+Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ kernel/trace/trace_events_hist.c | 24 ++++++++++++++++++------
+ 1 file changed, 18 insertions(+), 6 deletions(-)
+
+diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
+index ad7419e240556..53dc6719181e5 100644
+--- a/kernel/trace/trace_events_hist.c
++++ b/kernel/trace/trace_events_hist.c
+@@ -5689,12 +5689,16 @@ static int event_hist_open(struct inode *inode, struct file *file)
+       guard(mutex)(&event_mutex);
+       event_file = event_file_data(file);
+-      if (!event_file)
+-              return -ENODEV;
++      if (!event_file) {
++              ret = -ENODEV;
++              goto err;
++      }
+       hist_file = kzalloc(sizeof(*hist_file), GFP_KERNEL);
+-      if (!hist_file)
+-              return -ENOMEM;
++      if (!hist_file) {
++              ret = -ENOMEM;
++              goto err;
++      }
+       hist_file->file = file;
+       hist_file->last_act = get_hist_hit_count(event_file);
+@@ -5702,9 +5706,14 @@ static int event_hist_open(struct inode *inode, struct file *file)
+       /* Clear private_data to avoid warning in single_open() */
+       file->private_data = NULL;
+       ret = single_open(file, hist_show, hist_file);
+-      if (ret)
++      if (ret) {
+               kfree(hist_file);
++              goto err;
++      }
++      return 0;
++err:
++      tracing_release_file_tr(inode, file);
+       return ret;
+ }
+@@ -5979,7 +5988,10 @@ static int event_hist_debug_open(struct inode *inode, struct file *file)
+       /* Clear private_data to avoid warning in single_open() */
+       file->private_data = NULL;
+-      return single_open(file, hist_debug_show, file);
++      ret = single_open(file, hist_debug_show, file);
++      if (ret)
++              tracing_release_file_tr(inode, file);
++      return ret;
+ }
+ const struct file_operations event_hist_debug_fops = {
+-- 
+2.39.5
+
diff --git a/queue-6.13/tracing-hist-add-poll-pollin-support-on-hist-file.patch b/queue-6.13/tracing-hist-add-poll-pollin-support-on-hist-file.patch
new file mode 100644 (file)
index 0000000..fcd13d0
--- /dev/null
@@ -0,0 +1,216 @@
+From 643b94e5e1d83f39a4b66e913ea20acb9761cc78 Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Fri, 27 Dec 2024 13:07:57 +0900
+Subject: tracing/hist: Add poll(POLLIN) support on hist file
+
+From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
+
+[ Upstream commit 1bd13edbbed6e7e396f1aab92b224a4775218e68 ]
+
+Add poll syscall support on the `hist` file. The Waiter will be waken
+up when the histogram is updated with POLLIN.
+
+Currently, there is no way to wait for a specific event in userspace.
+So user needs to peek the `trace` periodicaly, or wait on `trace_pipe`.
+But it is not a good idea to peek at the `trace` for an event that
+randomly happens. And `trace_pipe` is not coming back until a page is
+filled with events.
+
+This allows a user to wait for a specific event on the `hist` file. User
+can set a histogram trigger on the event which they want to monitor
+and poll() on its `hist` file. Since this poll() returns POLLIN, the next
+poll() will return soon unless a read() happens on that hist file.
+
+NOTE: To read the hist file again, you must set the file offset to 0,
+but just for monitoring the event, you may not need to read the
+histogram.
+
+Cc: Shuah Khan <shuah@kernel.org>
+Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+Link: https://lore.kernel.org/173527247756.464571.14236296701625509931.stgit@devnote2
+Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
+Reviewed-by: Tom Zanussi <zanussi@kernel.org>
+Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
+Stable-dep-of: 0b4ffbe4888a ("tracing: Correct the refcount if the hist/hist_debug file fails to open")
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ include/linux/trace_events.h     | 14 +++++++
+ kernel/trace/trace_events.c      | 14 +++++++
+ kernel/trace/trace_events_hist.c | 70 ++++++++++++++++++++++++++++++--
+ 3 files changed, 95 insertions(+), 3 deletions(-)
+
+diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
+index 58ad4ead33fcd..5caea596fef0c 100644
+--- a/include/linux/trace_events.h
++++ b/include/linux/trace_events.h
+@@ -673,6 +673,20 @@ struct trace_event_file {
+       atomic_t                tm_ref; /* trigger-mode reference counter */
+ };
++#ifdef CONFIG_HIST_TRIGGERS
++extern struct irq_work hist_poll_work;
++extern wait_queue_head_t hist_poll_wq;
++
++static inline void hist_poll_wakeup(void)
++{
++      if (wq_has_sleeper(&hist_poll_wq))
++              irq_work_queue(&hist_poll_work);
++}
++
++#define hist_poll_wait(file, wait)    \
++      poll_wait(file, &hist_poll_wq, wait)
++#endif
++
+ #define __TRACE_EVENT_FLAGS(name, value)                              \
+       static int __init trace_init_flags_##name(void)                 \
+       {                                                               \
+diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
+index 770e7ed917161..4bb16d6f2d6fd 100644
+--- a/kernel/trace/trace_events.c
++++ b/kernel/trace/trace_events.c
+@@ -3111,6 +3111,20 @@ static bool event_in_systems(struct trace_event_call *call,
+       return !*p || isspace(*p) || *p == ',';
+ }
++#ifdef CONFIG_HIST_TRIGGERS
++/*
++ * Wake up waiter on the hist_poll_wq from irq_work because the hist trigger
++ * may happen in any context.
++ */
++static void hist_poll_event_irq_work(struct irq_work *work)
++{
++      wake_up_all(&hist_poll_wq);
++}
++
++DEFINE_IRQ_WORK(hist_poll_work, hist_poll_event_irq_work);
++DECLARE_WAIT_QUEUE_HEAD(hist_poll_wq);
++#endif
++
+ static struct trace_event_file *
+ trace_create_new_event(struct trace_event_call *call,
+                      struct trace_array *tr)
+diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
+index dfd568054f41e..a98753475a3fe 100644
+--- a/kernel/trace/trace_events_hist.c
++++ b/kernel/trace/trace_events_hist.c
+@@ -5311,6 +5311,8 @@ static void event_hist_trigger(struct event_trigger_data *data,
+       if (resolve_var_refs(hist_data, key, var_ref_vals, true))
+               hist_trigger_actions(hist_data, elt, buffer, rec, rbe, key, var_ref_vals);
++
++      hist_poll_wakeup();
+ }
+ static void hist_trigger_stacktrace_print(struct seq_file *m,
+@@ -5590,15 +5592,36 @@ static void hist_trigger_show(struct seq_file *m,
+                  n_entries, (u64)atomic64_read(&hist_data->map->drops));
+ }
++struct hist_file_data {
++      struct file *file;
++      u64 last_read;
++};
++
++static u64 get_hist_hit_count(struct trace_event_file *event_file)
++{
++      struct hist_trigger_data *hist_data;
++      struct event_trigger_data *data;
++      u64 ret = 0;
++
++      list_for_each_entry(data, &event_file->triggers, list) {
++              if (data->cmd_ops->trigger_type == ETT_EVENT_HIST) {
++                      hist_data = data->private_data;
++                      ret += atomic64_read(&hist_data->map->hits);
++              }
++      }
++      return ret;
++}
++
+ static int hist_show(struct seq_file *m, void *v)
+ {
++      struct hist_file_data *hist_file = m->private;
+       struct event_trigger_data *data;
+       struct trace_event_file *event_file;
+       int n = 0;
+       guard(mutex)(&event_mutex);
+-      event_file = event_file_file(m->private);
++      event_file = event_file_file(hist_file->file);
+       if (unlikely(!event_file))
+               return -ENODEV;
+@@ -5606,27 +5629,68 @@ static int hist_show(struct seq_file *m, void *v)
+               if (data->cmd_ops->trigger_type == ETT_EVENT_HIST)
+                       hist_trigger_show(m, data, n++);
+       }
++      hist_file->last_read = get_hist_hit_count(event_file);
++
+       return 0;
+ }
++static __poll_t event_hist_poll(struct file *file, struct poll_table_struct *wait)
++{
++      struct trace_event_file *event_file;
++      struct seq_file *m = file->private_data;
++      struct hist_file_data *hist_file = m->private;
++
++      guard(mutex)(&event_mutex);
++
++      event_file = event_file_data(file);
++      if (!event_file)
++              return EPOLLERR;
++
++      hist_poll_wait(file, wait);
++
++      if (hist_file->last_read != get_hist_hit_count(event_file))
++              return EPOLLIN | EPOLLRDNORM;
++
++      return 0;
++}
++
++static int event_hist_release(struct inode *inode, struct file *file)
++{
++      struct seq_file *m = file->private_data;
++      struct hist_file_data *hist_file = m->private;
++
++      kfree(hist_file);
++      return tracing_single_release_file_tr(inode, file);
++}
++
+ static int event_hist_open(struct inode *inode, struct file *file)
+ {
++      struct hist_file_data *hist_file;
+       int ret;
+       ret = tracing_open_file_tr(inode, file);
+       if (ret)
+               return ret;
++      hist_file = kzalloc(sizeof(*hist_file), GFP_KERNEL);
++      if (!hist_file)
++              return -ENOMEM;
++      hist_file->file = file;
++
+       /* Clear private_data to avoid warning in single_open() */
+       file->private_data = NULL;
+-      return single_open(file, hist_show, file);
++      ret = single_open(file, hist_show, hist_file);
++      if (ret)
++              kfree(hist_file);
++      return ret;
+ }
+ const struct file_operations event_hist_fops = {
+       .open = event_hist_open,
+       .read = seq_read,
+       .llseek = seq_lseek,
+-      .release = tracing_single_release_file_tr,
++      .release = event_hist_release,
++      .poll = event_hist_poll,
+ };
+ #ifdef CONFIG_HIST_TRIGGERS_DEBUG
+-- 
+2.39.5
+
diff --git a/queue-6.13/tracing-hist-support-pollpri-event-for-poll-on-histo.patch b/queue-6.13/tracing-hist-support-pollpri-event-for-poll-on-histo.patch
new file mode 100644 (file)
index 0000000..10f53e0
--- /dev/null
@@ -0,0 +1,119 @@
+From 4228007126dc4dc354f7fb3fa724b2ddde735fbd Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Fri, 27 Dec 2024 13:08:07 +0900
+Subject: tracing/hist: Support POLLPRI event for poll on histogram
+
+From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
+
+[ Upstream commit 66fc6f521a0b91051ce6968a216a30bc52267bf8 ]
+
+Since POLLIN will not be flushed until the hist file is read, the user
+needs to repeatedly read() and poll() on the hist file for monitoring the
+event continuously. But the read() is somewhat redundant when the user is
+only monitoring for event updates.
+
+Add POLLPRI poll event on the hist file so the event returns when a
+histogram is updated after open(), poll() or read(). Thus it is possible
+to wait for the next event without having to issue a read().
+
+Cc: Shuah Khan <shuah@kernel.org>
+Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+Link: https://lore.kernel.org/173527248770.464571.2536902137325258133.stgit@devnote2
+Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
+Reviewed-by: Tom Zanussi <zanussi@kernel.org>
+Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
+Stable-dep-of: 0b4ffbe4888a ("tracing: Correct the refcount if the hist/hist_debug file fails to open")
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ kernel/trace/trace_events_hist.c | 29 ++++++++++++++++++++++++++---
+ 1 file changed, 26 insertions(+), 3 deletions(-)
+
+diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
+index a98753475a3fe..ad7419e240556 100644
+--- a/kernel/trace/trace_events_hist.c
++++ b/kernel/trace/trace_events_hist.c
+@@ -5595,6 +5595,7 @@ static void hist_trigger_show(struct seq_file *m,
+ struct hist_file_data {
+       struct file *file;
+       u64 last_read;
++      u64 last_act;
+ };
+ static u64 get_hist_hit_count(struct trace_event_file *event_file)
+@@ -5630,6 +5631,11 @@ static int hist_show(struct seq_file *m, void *v)
+                       hist_trigger_show(m, data, n++);
+       }
+       hist_file->last_read = get_hist_hit_count(event_file);
++      /*
++       * Update last_act too so that poll()/POLLPRI can wait for the next
++       * event after any syscall on hist file.
++       */
++      hist_file->last_act = hist_file->last_read;
+       return 0;
+ }
+@@ -5639,6 +5645,8 @@ static __poll_t event_hist_poll(struct file *file, struct poll_table_struct *wai
+       struct trace_event_file *event_file;
+       struct seq_file *m = file->private_data;
+       struct hist_file_data *hist_file = m->private;
++      __poll_t ret = 0;
++      u64 cnt;
+       guard(mutex)(&event_mutex);
+@@ -5648,10 +5656,15 @@ static __poll_t event_hist_poll(struct file *file, struct poll_table_struct *wai
+       hist_poll_wait(file, wait);
+-      if (hist_file->last_read != get_hist_hit_count(event_file))
+-              return EPOLLIN | EPOLLRDNORM;
++      cnt = get_hist_hit_count(event_file);
++      if (hist_file->last_read != cnt)
++              ret |= EPOLLIN | EPOLLRDNORM;
++      if (hist_file->last_act != cnt) {
++              hist_file->last_act = cnt;
++              ret |= EPOLLPRI;
++      }
+-      return 0;
++      return ret;
+ }
+ static int event_hist_release(struct inode *inode, struct file *file)
+@@ -5665,6 +5678,7 @@ static int event_hist_release(struct inode *inode, struct file *file)
+ static int event_hist_open(struct inode *inode, struct file *file)
+ {
++      struct trace_event_file *event_file;
+       struct hist_file_data *hist_file;
+       int ret;
+@@ -5672,16 +5686,25 @@ static int event_hist_open(struct inode *inode, struct file *file)
+       if (ret)
+               return ret;
++      guard(mutex)(&event_mutex);
++
++      event_file = event_file_data(file);
++      if (!event_file)
++              return -ENODEV;
++
+       hist_file = kzalloc(sizeof(*hist_file), GFP_KERNEL);
+       if (!hist_file)
+               return -ENOMEM;
++
+       hist_file->file = file;
++      hist_file->last_act = get_hist_hit_count(event_file);
+       /* Clear private_data to avoid warning in single_open() */
+       file->private_data = NULL;
+       ret = single_open(file, hist_show, hist_file);
+       if (ret)
+               kfree(hist_file);
++
+       return ret;
+ }
+-- 
+2.39.5
+
diff --git a/queue-6.13/tracing-switch-trace_events_hist.c-code-over-to-use-.patch b/queue-6.13/tracing-switch-trace_events_hist.c-code-over-to-use-.patch
new file mode 100644 (file)
index 0000000..b45063d
--- /dev/null
@@ -0,0 +1,99 @@
+From 2657f92028dbb7dbde8ab3591424efbb60c21bde Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Thu, 19 Dec 2024 15:12:05 -0500
+Subject: tracing: Switch trace_events_hist.c code over to use guard()
+
+From: Steven Rostedt <rostedt@goodmis.org>
+
+[ Upstream commit 2b36a97aeeb71b1e4a48bfedc7f21f44aeb1e6fb ]
+
+There are a couple functions in trace_events_hist.c that have "goto out" or
+equivalent on error in order to release locks that were taken. This can be
+error prone or just simply make the code more complex.
+
+Switch every location that ends with unlocking a mutex on error over to
+using the guard(mutex)() infrastructure to let the compiler worry about
+releasing locks. This makes the code easier to read and understand.
+
+Cc: Masami Hiramatsu <mhiramat@kernel.org>
+Cc: Mark Rutland <mark.rutland@arm.com>
+Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+Cc: Andrew Morton <akpm@linux-foundation.org>
+Cc: Peter Zijlstra <peterz@infradead.org>
+Link: https://lore.kernel.org/20241219201345.694601480@goodmis.org
+Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
+Stable-dep-of: 0b4ffbe4888a ("tracing: Correct the refcount if the hist/hist_debug file fails to open")
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ kernel/trace/trace_events_hist.c | 32 ++++++++++----------------------
+ 1 file changed, 10 insertions(+), 22 deletions(-)
+
+diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
+index 89e5bcb915628..dfd568054f41e 100644
+--- a/kernel/trace/trace_events_hist.c
++++ b/kernel/trace/trace_events_hist.c
+@@ -5594,25 +5594,19 @@ static int hist_show(struct seq_file *m, void *v)
+ {
+       struct event_trigger_data *data;
+       struct trace_event_file *event_file;
+-      int n = 0, ret = 0;
++      int n = 0;
+-      mutex_lock(&event_mutex);
++      guard(mutex)(&event_mutex);
+       event_file = event_file_file(m->private);
+-      if (unlikely(!event_file)) {
+-              ret = -ENODEV;
+-              goto out_unlock;
+-      }
++      if (unlikely(!event_file))
++              return -ENODEV;
+       list_for_each_entry(data, &event_file->triggers, list) {
+               if (data->cmd_ops->trigger_type == ETT_EVENT_HIST)
+                       hist_trigger_show(m, data, n++);
+       }
+-
+- out_unlock:
+-      mutex_unlock(&event_mutex);
+-
+-      return ret;
++      return 0;
+ }
+ static int event_hist_open(struct inode *inode, struct file *file)
+@@ -5873,25 +5867,19 @@ static int hist_debug_show(struct seq_file *m, void *v)
+ {
+       struct event_trigger_data *data;
+       struct trace_event_file *event_file;
+-      int n = 0, ret = 0;
++      int n = 0;
+-      mutex_lock(&event_mutex);
++      guard(mutex)(&event_mutex);
+       event_file = event_file_file(m->private);
+-      if (unlikely(!event_file)) {
+-              ret = -ENODEV;
+-              goto out_unlock;
+-      }
++      if (unlikely(!event_file))
++              return -ENODEV;
+       list_for_each_entry(data, &event_file->triggers, list) {
+               if (data->cmd_ops->trigger_type == ETT_EVENT_HIST)
+                       hist_trigger_debug_show(m, data, n++);
+       }
+-
+- out_unlock:
+-      mutex_unlock(&event_mutex);
+-
+-      return ret;
++      return 0;
+ }
+ static int event_hist_debug_open(struct inode *inode, struct file *file)
+-- 
+2.39.5
+
diff --git a/queue-6.13/tty-serial-fsl_lpuart-use-port-struct-directly-to-si.patch b/queue-6.13/tty-serial-fsl_lpuart-use-port-struct-directly-to-si.patch
new file mode 100644 (file)
index 0000000..3ef732c
--- /dev/null
@@ -0,0 +1,523 @@
+From 9223be8453b362b46aff91a9d0f140f9c8b4e3d5 Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Wed, 12 Mar 2025 10:39:03 +0800
+Subject: tty: serial: fsl_lpuart: use port struct directly to simply code
+
+From: Sherry Sun <sherry.sun@nxp.com>
+
+[ Upstream commit 3cc16ae096f164ae0c6b98416c25a01db5f3a529 ]
+
+Most lpuart functions have the parameter struct uart_port *port, but
+still use the &sport->port to get the uart_port instead of use it
+directly, let's simply the code logic, directly use this struct instead
+of covert it from struct sport.
+
+Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
+Link: https://lore.kernel.org/r/20250312023904.1343351-3-sherry.sun@nxp.com
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Stable-dep-of: e98ab45ec518 ("tty: serial: lpuart: only disable CTS instead of overwriting the whole UARTMODIR register")
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ drivers/tty/serial/fsl_lpuart.c | 213 +++++++++++++++-----------------
+ 1 file changed, 102 insertions(+), 111 deletions(-)
+
+diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
+index 1afcfc40079d5..2971de64f6a3d 100644
+--- a/drivers/tty/serial/fsl_lpuart.c
++++ b/drivers/tty/serial/fsl_lpuart.c
+@@ -581,7 +581,7 @@ static int lpuart_dma_tx_request(struct uart_port *port)
+       ret = dmaengine_slave_config(sport->dma_tx_chan, &dma_tx_sconfig);
+       if (ret) {
+-              dev_err(sport->port.dev,
++              dev_err(port->dev,
+                               "DMA slave config failed, err = %d\n", ret);
+               return ret;
+       }
+@@ -611,13 +611,13 @@ static void lpuart_flush_buffer(struct uart_port *port)
+       }
+       if (lpuart_is_32(sport)) {
+-              val = lpuart32_read(&sport->port, UARTFIFO);
++              val = lpuart32_read(port, UARTFIFO);
+               val |= UARTFIFO_TXFLUSH | UARTFIFO_RXFLUSH;
+-              lpuart32_write(&sport->port, val, UARTFIFO);
++              lpuart32_write(port, val, UARTFIFO);
+       } else {
+-              val = readb(sport->port.membase + UARTCFIFO);
++              val = readb(port->membase + UARTCFIFO);
+               val |= UARTCFIFO_TXFLUSH | UARTCFIFO_RXFLUSH;
+-              writeb(val, sport->port.membase + UARTCFIFO);
++              writeb(val, port->membase + UARTCFIFO);
+       }
+ }
+@@ -639,38 +639,36 @@ static void lpuart32_wait_bit_set(struct uart_port *port, unsigned int offset,
+ static int lpuart_poll_init(struct uart_port *port)
+ {
+-      struct lpuart_port *sport = container_of(port,
+-                                      struct lpuart_port, port);
+       unsigned long flags;
+       u8 temp;
+-      sport->port.fifosize = 0;
++      port->fifosize = 0;
+-      uart_port_lock_irqsave(&sport->port, &flags);
++      uart_port_lock_irqsave(port, &flags);
+       /* Disable Rx & Tx */
+-      writeb(0, sport->port.membase + UARTCR2);
++      writeb(0, port->membase + UARTCR2);
+-      temp = readb(sport->port.membase + UARTPFIFO);
++      temp = readb(port->membase + UARTPFIFO);
+       /* Enable Rx and Tx FIFO */
+       writeb(temp | UARTPFIFO_RXFE | UARTPFIFO_TXFE,
+-                      sport->port.membase + UARTPFIFO);
++                      port->membase + UARTPFIFO);
+       /* flush Tx and Rx FIFO */
+       writeb(UARTCFIFO_TXFLUSH | UARTCFIFO_RXFLUSH,
+-                      sport->port.membase + UARTCFIFO);
++                      port->membase + UARTCFIFO);
+       /* explicitly clear RDRF */
+-      if (readb(sport->port.membase + UARTSR1) & UARTSR1_RDRF) {
+-              readb(sport->port.membase + UARTDR);
+-              writeb(UARTSFIFO_RXUF, sport->port.membase + UARTSFIFO);
++      if (readb(port->membase + UARTSR1) & UARTSR1_RDRF) {
++              readb(port->membase + UARTDR);
++              writeb(UARTSFIFO_RXUF, port->membase + UARTSFIFO);
+       }
+-      writeb(0, sport->port.membase + UARTTWFIFO);
+-      writeb(1, sport->port.membase + UARTRWFIFO);
++      writeb(0, port->membase + UARTTWFIFO);
++      writeb(1, port->membase + UARTRWFIFO);
+       /* Enable Rx and Tx */
+-      writeb(UARTCR2_RE | UARTCR2_TE, sport->port.membase + UARTCR2);
+-      uart_port_unlock_irqrestore(&sport->port, flags);
++      writeb(UARTCR2_RE | UARTCR2_TE, port->membase + UARTCR2);
++      uart_port_unlock_irqrestore(port, flags);
+       return 0;
+ }
+@@ -693,33 +691,32 @@ static int lpuart_poll_get_char(struct uart_port *port)
+ static int lpuart32_poll_init(struct uart_port *port)
+ {
+       unsigned long flags;
+-      struct lpuart_port *sport = container_of(port, struct lpuart_port, port);
+       u32 temp;
+-      sport->port.fifosize = 0;
++      port->fifosize = 0;
+-      uart_port_lock_irqsave(&sport->port, &flags);
++      uart_port_lock_irqsave(port, &flags);
+       /* Disable Rx & Tx */
+-      lpuart32_write(&sport->port, 0, UARTCTRL);
++      lpuart32_write(port, 0, UARTCTRL);
+-      temp = lpuart32_read(&sport->port, UARTFIFO);
++      temp = lpuart32_read(port, UARTFIFO);
+       /* Enable Rx and Tx FIFO */
+-      lpuart32_write(&sport->port, temp | UARTFIFO_RXFE | UARTFIFO_TXFE, UARTFIFO);
++      lpuart32_write(port, temp | UARTFIFO_RXFE | UARTFIFO_TXFE, UARTFIFO);
+       /* flush Tx and Rx FIFO */
+-      lpuart32_write(&sport->port, UARTFIFO_TXFLUSH | UARTFIFO_RXFLUSH, UARTFIFO);
++      lpuart32_write(port, UARTFIFO_TXFLUSH | UARTFIFO_RXFLUSH, UARTFIFO);
+       /* explicitly clear RDRF */
+-      if (lpuart32_read(&sport->port, UARTSTAT) & UARTSTAT_RDRF) {
+-              lpuart32_read(&sport->port, UARTDATA);
+-              lpuart32_write(&sport->port, UARTFIFO_RXUF, UARTFIFO);
++      if (lpuart32_read(port, UARTSTAT) & UARTSTAT_RDRF) {
++              lpuart32_read(port, UARTDATA);
++              lpuart32_write(port, UARTFIFO_RXUF, UARTFIFO);
+       }
+       /* Enable Rx and Tx */
+-      lpuart32_write(&sport->port, UARTCTRL_RE | UARTCTRL_TE, UARTCTRL);
+-      uart_port_unlock_irqrestore(&sport->port, flags);
++      lpuart32_write(port, UARTCTRL_RE | UARTCTRL_TE, UARTCTRL);
++      uart_port_unlock_irqrestore(port, flags);
+       return 0;
+ }
+@@ -1449,12 +1446,9 @@ static void lpuart_dma_rx_free(struct uart_port *port)
+ static int lpuart_config_rs485(struct uart_port *port, struct ktermios *termios,
+                       struct serial_rs485 *rs485)
+ {
+-      struct lpuart_port *sport = container_of(port,
+-                      struct lpuart_port, port);
+-
+-      u8 modem = readb(sport->port.membase + UARTMODEM) &
++      u8 modem = readb(port->membase + UARTMODEM) &
+               ~(UARTMODEM_TXRTSPOL | UARTMODEM_TXRTSE);
+-      writeb(modem, sport->port.membase + UARTMODEM);
++      writeb(modem, port->membase + UARTMODEM);
+       if (rs485->flags & SER_RS485_ENABLED) {
+               /* Enable auto RS-485 RTS mode */
+@@ -1472,32 +1466,29 @@ static int lpuart_config_rs485(struct uart_port *port, struct ktermios *termios,
+                       modem &= ~UARTMODEM_TXRTSPOL;
+       }
+-      writeb(modem, sport->port.membase + UARTMODEM);
++      writeb(modem, port->membase + UARTMODEM);
+       return 0;
+ }
+ static int lpuart32_config_rs485(struct uart_port *port, struct ktermios *termios,
+                       struct serial_rs485 *rs485)
+ {
+-      struct lpuart_port *sport = container_of(port,
+-                      struct lpuart_port, port);
+-
+-      u32 modem = lpuart32_read(&sport->port, UARTMODIR)
++      u32 modem = lpuart32_read(port, UARTMODIR)
+                               & ~(UARTMODIR_TXRTSPOL | UARTMODIR_TXRTSE);
+       u32 ctrl;
+       /* TXRTSE and TXRTSPOL only can be changed when transmitter is disabled. */
+-      ctrl = lpuart32_read(&sport->port, UARTCTRL);
++      ctrl = lpuart32_read(port, UARTCTRL);
+       if (ctrl & UARTCTRL_TE) {
+               /* wait for the transmit engine to complete */
+-              lpuart32_wait_bit_set(&sport->port, UARTSTAT, UARTSTAT_TC);
+-              lpuart32_write(&sport->port, ctrl & ~UARTCTRL_TE, UARTCTRL);
++              lpuart32_wait_bit_set(port, UARTSTAT, UARTSTAT_TC);
++              lpuart32_write(port, ctrl & ~UARTCTRL_TE, UARTCTRL);
+-              while (lpuart32_read(&sport->port, UARTCTRL) & UARTCTRL_TE)
++              while (lpuart32_read(port, UARTCTRL) & UARTCTRL_TE)
+                       cpu_relax();
+       }
+-      lpuart32_write(&sport->port, modem, UARTMODIR);
++      lpuart32_write(port, modem, UARTMODIR);
+       if (rs485->flags & SER_RS485_ENABLED) {
+               /* Enable auto RS-485 RTS mode */
+@@ -1515,10 +1506,10 @@ static int lpuart32_config_rs485(struct uart_port *port, struct ktermios *termio
+                       modem &= ~UARTMODIR_TXRTSPOL;
+       }
+-      lpuart32_write(&sport->port, modem, UARTMODIR);
++      lpuart32_write(port, modem, UARTMODIR);
+       if (ctrl & UARTCTRL_TE)
+-              lpuart32_write(&sport->port, ctrl, UARTCTRL);
++              lpuart32_write(port, ctrl, UARTCTRL);
+       return 0;
+ }
+@@ -1829,11 +1820,11 @@ static int lpuart_startup(struct uart_port *port)
+       u8 temp;
+       /* determine FIFO size and enable FIFO mode */
+-      temp = readb(sport->port.membase + UARTPFIFO);
++      temp = readb(port->membase + UARTPFIFO);
+       sport->txfifo_size = UARTFIFO_DEPTH((temp >> UARTPFIFO_TXSIZE_OFF) &
+                                           UARTPFIFO_FIFOSIZE_MASK);
+-      sport->port.fifosize = sport->txfifo_size;
++      port->fifosize = sport->txfifo_size;
+       sport->rxfifo_size = UARTFIFO_DEPTH((temp >> UARTPFIFO_RXSIZE_OFF) &
+                                           UARTPFIFO_FIFOSIZE_MASK);
+@@ -1889,11 +1880,11 @@ static int lpuart32_startup(struct uart_port *port)
+       u32 temp;
+       /* determine FIFO size */
+-      temp = lpuart32_read(&sport->port, UARTFIFO);
++      temp = lpuart32_read(port, UARTFIFO);
+       sport->txfifo_size = UARTFIFO_DEPTH((temp >> UARTFIFO_TXSIZE_OFF) &
+                                           UARTFIFO_FIFOSIZE_MASK);
+-      sport->port.fifosize = sport->txfifo_size;
++      port->fifosize = sport->txfifo_size;
+       sport->rxfifo_size = UARTFIFO_DEPTH((temp >> UARTFIFO_RXSIZE_OFF) &
+                                           UARTFIFO_FIFOSIZE_MASK);
+@@ -1906,7 +1897,7 @@ static int lpuart32_startup(struct uart_port *port)
+       if (is_layerscape_lpuart(sport)) {
+               sport->rxfifo_size = 16;
+               sport->txfifo_size = 16;
+-              sport->port.fifosize = sport->txfifo_size;
++              port->fifosize = sport->txfifo_size;
+       }
+       lpuart_request_dma(sport);
+@@ -1966,8 +1957,8 @@ static void lpuart32_shutdown(struct uart_port *port)
+       uart_port_lock_irqsave(port, &flags);
+       /* clear status */
+-      temp = lpuart32_read(&sport->port, UARTSTAT);
+-      lpuart32_write(&sport->port, temp, UARTSTAT);
++      temp = lpuart32_read(port, UARTSTAT);
++      lpuart32_write(port, temp, UARTSTAT);
+       /* disable Rx/Tx DMA */
+       temp = lpuart32_read(port, UARTBAUD);
+@@ -1996,12 +1987,12 @@ lpuart_set_termios(struct uart_port *port, struct ktermios *termios,
+       unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
+       unsigned int sbr, brfa;
+-      cr1 = old_cr1 = readb(sport->port.membase + UARTCR1);
+-      old_cr2 = readb(sport->port.membase + UARTCR2);
+-      cr3 = readb(sport->port.membase + UARTCR3);
+-      cr4 = readb(sport->port.membase + UARTCR4);
+-      bdh = readb(sport->port.membase + UARTBDH);
+-      modem = readb(sport->port.membase + UARTMODEM);
++      cr1 = old_cr1 = readb(port->membase + UARTCR1);
++      old_cr2 = readb(port->membase + UARTCR2);
++      cr3 = readb(port->membase + UARTCR3);
++      cr4 = readb(port->membase + UARTCR4);
++      bdh = readb(port->membase + UARTBDH);
++      modem = readb(port->membase + UARTMODEM);
+       /*
+        * only support CS8 and CS7, and for CS7 must enable PE.
+        * supported mode:
+@@ -2033,7 +2024,7 @@ lpuart_set_termios(struct uart_port *port, struct ktermios *termios,
+        * When auto RS-485 RTS mode is enabled,
+        * hardware flow control need to be disabled.
+        */
+-      if (sport->port.rs485.flags & SER_RS485_ENABLED)
++      if (port->rs485.flags & SER_RS485_ENABLED)
+               termios->c_cflag &= ~CRTSCTS;
+       if (termios->c_cflag & CRTSCTS)
+@@ -2074,59 +2065,59 @@ lpuart_set_termios(struct uart_port *port, struct ktermios *termios,
+        * Need to update the Ring buffer length according to the selected
+        * baud rate and restart Rx DMA path.
+        *
+-       * Since timer function acqures sport->port.lock, need to stop before
++       * Since timer function acqures port->lock, need to stop before
+        * acquring same lock because otherwise del_timer_sync() can deadlock.
+        */
+       if (old && sport->lpuart_dma_rx_use)
+-              lpuart_dma_rx_free(&sport->port);
++              lpuart_dma_rx_free(port);
+-      uart_port_lock_irqsave(&sport->port, &flags);
++      uart_port_lock_irqsave(port, &flags);
+-      sport->port.read_status_mask = 0;
++      port->read_status_mask = 0;
+       if (termios->c_iflag & INPCK)
+-              sport->port.read_status_mask |= UARTSR1_FE | UARTSR1_PE;
++              port->read_status_mask |= UARTSR1_FE | UARTSR1_PE;
+       if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK))
+-              sport->port.read_status_mask |= UARTSR1_FE;
++              port->read_status_mask |= UARTSR1_FE;
+       /* characters to ignore */
+-      sport->port.ignore_status_mask = 0;
++      port->ignore_status_mask = 0;
+       if (termios->c_iflag & IGNPAR)
+-              sport->port.ignore_status_mask |= UARTSR1_PE;
++              port->ignore_status_mask |= UARTSR1_PE;
+       if (termios->c_iflag & IGNBRK) {
+-              sport->port.ignore_status_mask |= UARTSR1_FE;
++              port->ignore_status_mask |= UARTSR1_FE;
+               /*
+                * if we're ignoring parity and break indicators,
+                * ignore overruns too (for real raw support).
+                */
+               if (termios->c_iflag & IGNPAR)
+-                      sport->port.ignore_status_mask |= UARTSR1_OR;
++                      port->ignore_status_mask |= UARTSR1_OR;
+       }
+       /* update the per-port timeout */
+       uart_update_timeout(port, termios->c_cflag, baud);
+       /* wait transmit engin complete */
+-      lpuart_wait_bit_set(&sport->port, UARTSR1, UARTSR1_TC);
++      lpuart_wait_bit_set(port, UARTSR1, UARTSR1_TC);
+       /* disable transmit and receive */
+       writeb(old_cr2 & ~(UARTCR2_TE | UARTCR2_RE),
+-                      sport->port.membase + UARTCR2);
++                      port->membase + UARTCR2);
+-      sbr = sport->port.uartclk / (16 * baud);
+-      brfa = ((sport->port.uartclk - (16 * sbr * baud)) * 2) / baud;
++      sbr = port->uartclk / (16 * baud);
++      brfa = ((port->uartclk - (16 * sbr * baud)) * 2) / baud;
+       bdh &= ~UARTBDH_SBR_MASK;
+       bdh |= (sbr >> 8) & 0x1F;
+       cr4 &= ~UARTCR4_BRFA_MASK;
+       brfa &= UARTCR4_BRFA_MASK;
+-      writeb(cr4 | brfa, sport->port.membase + UARTCR4);
+-      writeb(bdh, sport->port.membase + UARTBDH);
+-      writeb(sbr & 0xFF, sport->port.membase + UARTBDL);
+-      writeb(cr3, sport->port.membase + UARTCR3);
+-      writeb(cr1, sport->port.membase + UARTCR1);
+-      writeb(modem, sport->port.membase + UARTMODEM);
++      writeb(cr4 | brfa, port->membase + UARTCR4);
++      writeb(bdh, port->membase + UARTBDH);
++      writeb(sbr & 0xFF, port->membase + UARTBDL);
++      writeb(cr3, port->membase + UARTCR3);
++      writeb(cr1, port->membase + UARTCR1);
++      writeb(modem, port->membase + UARTMODEM);
+       /* restore control register */
+-      writeb(old_cr2, sport->port.membase + UARTCR2);
++      writeb(old_cr2, port->membase + UARTCR2);
+       if (old && sport->lpuart_dma_rx_use) {
+               if (!lpuart_start_rx_dma(sport))
+@@ -2135,7 +2126,7 @@ lpuart_set_termios(struct uart_port *port, struct ktermios *termios,
+                       sport->lpuart_dma_rx_use = false;
+       }
+-      uart_port_unlock_irqrestore(&sport->port, flags);
++      uart_port_unlock_irqrestore(port, flags);
+ }
+ static void __lpuart32_serial_setbrg(struct uart_port *port,
+@@ -2233,9 +2224,9 @@ lpuart32_set_termios(struct uart_port *port, struct ktermios *termios,
+       unsigned int  baud;
+       unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
+-      ctrl = old_ctrl = lpuart32_read(&sport->port, UARTCTRL);
+-      bd = lpuart32_read(&sport->port, UARTBAUD);
+-      modem = lpuart32_read(&sport->port, UARTMODIR);
++      ctrl = old_ctrl = lpuart32_read(port, UARTCTRL);
++      bd = lpuart32_read(port, UARTBAUD);
++      modem = lpuart32_read(port, UARTMODIR);
+       sport->is_cs7 = false;
+       /*
+        * only support CS8 and CS7
+@@ -2269,7 +2260,7 @@ lpuart32_set_termios(struct uart_port *port, struct ktermios *termios,
+        * When auto RS-485 RTS mode is enabled,
+        * hardware flow control need to be disabled.
+        */
+-      if (sport->port.rs485.flags & SER_RS485_ENABLED)
++      if (port->rs485.flags & SER_RS485_ENABLED)
+               termios->c_cflag &= ~CRTSCTS;
+       if (termios->c_cflag & CRTSCTS)
+@@ -2319,32 +2310,32 @@ lpuart32_set_termios(struct uart_port *port, struct ktermios *termios,
+        * Need to update the Ring buffer length according to the selected
+        * baud rate and restart Rx DMA path.
+        *
+-       * Since timer function acqures sport->port.lock, need to stop before
++       * Since timer function acqures port->lock, need to stop before
+        * acquring same lock because otherwise del_timer_sync() can deadlock.
+        */
+       if (old && sport->lpuart_dma_rx_use)
+-              lpuart_dma_rx_free(&sport->port);
++              lpuart_dma_rx_free(port);
+-      uart_port_lock_irqsave(&sport->port, &flags);
++      uart_port_lock_irqsave(port, &flags);
+-      sport->port.read_status_mask = 0;
++      port->read_status_mask = 0;
+       if (termios->c_iflag & INPCK)
+-              sport->port.read_status_mask |= UARTSTAT_FE | UARTSTAT_PE;
++              port->read_status_mask |= UARTSTAT_FE | UARTSTAT_PE;
+       if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK))
+-              sport->port.read_status_mask |= UARTSTAT_FE;
++              port->read_status_mask |= UARTSTAT_FE;
+       /* characters to ignore */
+-      sport->port.ignore_status_mask = 0;
++      port->ignore_status_mask = 0;
+       if (termios->c_iflag & IGNPAR)
+-              sport->port.ignore_status_mask |= UARTSTAT_PE;
++              port->ignore_status_mask |= UARTSTAT_PE;
+       if (termios->c_iflag & IGNBRK) {
+-              sport->port.ignore_status_mask |= UARTSTAT_FE;
++              port->ignore_status_mask |= UARTSTAT_FE;
+               /*
+                * if we're ignoring parity and break indicators,
+                * ignore overruns too (for real raw support).
+                */
+               if (termios->c_iflag & IGNPAR)
+-                      sport->port.ignore_status_mask |= UARTSTAT_OR;
++                      port->ignore_status_mask |= UARTSTAT_OR;
+       }
+       /* update the per-port timeout */
+@@ -2356,22 +2347,22 @@ lpuart32_set_termios(struct uart_port *port, struct ktermios *termios,
+        * asserted.
+        */
+       if (!(old_ctrl & UARTCTRL_SBK)) {
+-              lpuart32_write(&sport->port, 0, UARTMODIR);
+-              lpuart32_wait_bit_set(&sport->port, UARTSTAT, UARTSTAT_TC);
++              lpuart32_write(port, 0, UARTMODIR);
++              lpuart32_wait_bit_set(port, UARTSTAT, UARTSTAT_TC);
+       }
+       /* disable transmit and receive */
+-      lpuart32_write(&sport->port, old_ctrl & ~(UARTCTRL_TE | UARTCTRL_RE),
++      lpuart32_write(port, old_ctrl & ~(UARTCTRL_TE | UARTCTRL_RE),
+                      UARTCTRL);
+-      lpuart32_write(&sport->port, bd, UARTBAUD);
++      lpuart32_write(port, bd, UARTBAUD);
+       lpuart32_serial_setbrg(sport, baud);
+       /* disable CTS before enabling UARTCTRL_TE to avoid pending idle preamble */
+-      lpuart32_write(&sport->port, modem & ~UARTMODIR_TXCTSE, UARTMODIR);
++      lpuart32_write(port, modem & ~UARTMODIR_TXCTSE, UARTMODIR);
+       /* restore control register */
+-      lpuart32_write(&sport->port, ctrl, UARTCTRL);
++      lpuart32_write(port, ctrl, UARTCTRL);
+       /* re-enable the CTS if needed */
+-      lpuart32_write(&sport->port, modem, UARTMODIR);
++      lpuart32_write(port, modem, UARTMODIR);
+       if ((ctrl & (UARTCTRL_PE | UARTCTRL_M)) == UARTCTRL_PE)
+               sport->is_cs7 = true;
+@@ -2383,7 +2374,7 @@ lpuart32_set_termios(struct uart_port *port, struct ktermios *termios,
+                       sport->lpuart_dma_rx_use = false;
+       }
+-      uart_port_unlock_irqrestore(&sport->port, flags);
++      uart_port_unlock_irqrestore(port, flags);
+ }
+ static const char *lpuart_type(struct uart_port *port)
+@@ -2821,7 +2812,7 @@ static int lpuart_global_reset(struct lpuart_port *sport)
+       ret = clk_prepare_enable(sport->ipg_clk);
+       if (ret) {
+-              dev_err(sport->port.dev, "failed to enable uart ipg clk: %d\n", ret);
++              dev_err(port->dev, "failed to enable uart ipg clk: %d\n", ret);
+               return ret;
+       }
+@@ -2832,10 +2823,10 @@ static int lpuart_global_reset(struct lpuart_port *sport)
+                */
+               ctrl = lpuart32_read(port, UARTCTRL);
+               if (ctrl & UARTCTRL_TE) {
+-                      bd = lpuart32_read(&sport->port, UARTBAUD);
++                      bd = lpuart32_read(port, UARTBAUD);
+                       if (read_poll_timeout(lpuart32_tx_empty, val, val, 1, 100000, false,
+                                             port)) {
+-                              dev_warn(sport->port.dev,
++                              dev_warn(port->dev,
+                                        "timeout waiting for transmit engine to complete\n");
+                               clk_disable_unprepare(sport->ipg_clk);
+                               return 0;
+@@ -3187,7 +3178,7 @@ static void lpuart_console_fixup(struct lpuart_port *sport)
+        * in VLLS mode, or restore console setting here.
+        */
+       if (is_imx7ulp_lpuart(sport) && lpuart_uport_is_active(sport) &&
+-          console_suspend_enabled && uart_console(&sport->port)) {
++          console_suspend_enabled && uart_console(uport)) {
+               mutex_lock(&port->mutex);
+               memset(&termios, 0, sizeof(struct ktermios));
+-- 
+2.39.5
+
diff --git a/queue-6.13/tty-serial-fsl_lpuart-use-u32-and-u8-for-register-va.patch b/queue-6.13/tty-serial-fsl_lpuart-use-u32-and-u8-for-register-va.patch
new file mode 100644 (file)
index 0000000..6c37ad6
--- /dev/null
@@ -0,0 +1,407 @@
+From 194bdaf96a3b9704af2a3f0ff38fb30cec8b4c2a Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Wed, 12 Mar 2025 10:39:02 +0800
+Subject: tty: serial: fsl_lpuart: Use u32 and u8 for register variables
+
+From: Sherry Sun <sherry.sun@nxp.com>
+
+[ Upstream commit b6a8f6ab2c53e5ea3c7f2a3978db378a89bb7595 ]
+
+Use u32 and u8 rather than unsigned long or unsigned char for register
+variables for clarity and consistency.
+
+Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
+Link: https://lore.kernel.org/r/20250312023904.1343351-2-sherry.sun@nxp.com
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Stable-dep-of: e98ab45ec518 ("tty: serial: lpuart: only disable CTS instead of overwriting the whole UARTMODIR register")
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ drivers/tty/serial/fsl_lpuart.c | 93 ++++++++++++++++-----------------
+ 1 file changed, 46 insertions(+), 47 deletions(-)
+
+diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
+index 433cf2267e162..1afcfc40079d5 100644
+--- a/drivers/tty/serial/fsl_lpuart.c
++++ b/drivers/tty/serial/fsl_lpuart.c
+@@ -441,7 +441,7 @@ static unsigned int lpuart_get_baud_clk_rate(struct lpuart_port *sport)
+ static void lpuart_stop_tx(struct uart_port *port)
+ {
+-      unsigned char temp;
++      u8 temp;
+       temp = readb(port->membase + UARTCR2);
+       temp &= ~(UARTCR2_TIE | UARTCR2_TCIE);
+@@ -450,7 +450,7 @@ static void lpuart_stop_tx(struct uart_port *port)
+ static void lpuart32_stop_tx(struct uart_port *port)
+ {
+-      unsigned long temp;
++      u32 temp;
+       temp = lpuart32_read(port, UARTCTRL);
+       temp &= ~(UARTCTRL_TIE | UARTCTRL_TCIE);
+@@ -459,7 +459,7 @@ static void lpuart32_stop_tx(struct uart_port *port)
+ static void lpuart_stop_rx(struct uart_port *port)
+ {
+-      unsigned char temp;
++      u8 temp;
+       temp = readb(port->membase + UARTCR2);
+       writeb(temp & ~UARTCR2_RE, port->membase + UARTCR2);
+@@ -467,7 +467,7 @@ static void lpuart_stop_rx(struct uart_port *port)
+ static void lpuart32_stop_rx(struct uart_port *port)
+ {
+-      unsigned long temp;
++      u32 temp;
+       temp = lpuart32_read(port, UARTCTRL);
+       lpuart32_write(port, temp & ~UARTCTRL_RE, UARTCTRL);
+@@ -642,7 +642,7 @@ static int lpuart_poll_init(struct uart_port *port)
+       struct lpuart_port *sport = container_of(port,
+                                       struct lpuart_port, port);
+       unsigned long flags;
+-      unsigned char temp;
++      u8 temp;
+       sport->port.fifosize = 0;
+@@ -752,7 +752,7 @@ static inline void lpuart_transmit_buffer(struct lpuart_port *sport)
+ static inline void lpuart32_transmit_buffer(struct lpuart_port *sport)
+ {
+       struct tty_port *tport = &sport->port.state->port;
+-      unsigned long txcnt;
++      u32 txcnt;
+       unsigned char c;
+       if (sport->port.x_char) {
+@@ -789,7 +789,7 @@ static void lpuart_start_tx(struct uart_port *port)
+ {
+       struct lpuart_port *sport = container_of(port,
+                       struct lpuart_port, port);
+-      unsigned char temp;
++      u8 temp;
+       temp = readb(port->membase + UARTCR2);
+       writeb(temp | UARTCR2_TIE, port->membase + UARTCR2);
+@@ -806,7 +806,7 @@ static void lpuart_start_tx(struct uart_port *port)
+ static void lpuart32_start_tx(struct uart_port *port)
+ {
+       struct lpuart_port *sport = container_of(port, struct lpuart_port, port);
+-      unsigned long temp;
++      u32 temp;
+       if (sport->lpuart_dma_tx_use) {
+               if (!lpuart_stopped_or_empty(port))
+@@ -839,8 +839,8 @@ static unsigned int lpuart_tx_empty(struct uart_port *port)
+ {
+       struct lpuart_port *sport = container_of(port,
+                       struct lpuart_port, port);
+-      unsigned char sr1 = readb(port->membase + UARTSR1);
+-      unsigned char sfifo = readb(port->membase + UARTSFIFO);
++      u8 sr1 = readb(port->membase + UARTSR1);
++      u8 sfifo = readb(port->membase + UARTSFIFO);
+       if (sport->dma_tx_in_progress)
+               return 0;
+@@ -855,9 +855,9 @@ static unsigned int lpuart32_tx_empty(struct uart_port *port)
+ {
+       struct lpuart_port *sport = container_of(port,
+                       struct lpuart_port, port);
+-      unsigned long stat = lpuart32_read(port, UARTSTAT);
+-      unsigned long sfifo = lpuart32_read(port, UARTFIFO);
+-      unsigned long ctrl = lpuart32_read(port, UARTCTRL);
++      u32 stat = lpuart32_read(port, UARTSTAT);
++      u32 sfifo = lpuart32_read(port, UARTFIFO);
++      u32 ctrl = lpuart32_read(port, UARTCTRL);
+       if (sport->dma_tx_in_progress)
+               return 0;
+@@ -884,7 +884,7 @@ static void lpuart_rxint(struct lpuart_port *sport)
+ {
+       unsigned int flg, ignored = 0, overrun = 0;
+       struct tty_port *port = &sport->port.state->port;
+-      unsigned char rx, sr;
++      u8 rx, sr;
+       uart_port_lock(&sport->port);
+@@ -961,7 +961,7 @@ static void lpuart32_rxint(struct lpuart_port *sport)
+ {
+       unsigned int flg, ignored = 0;
+       struct tty_port *port = &sport->port.state->port;
+-      unsigned long rx, sr;
++      u32 rx, sr;
+       bool is_break;
+       uart_port_lock(&sport->port);
+@@ -1039,7 +1039,7 @@ static void lpuart32_rxint(struct lpuart_port *sport)
+ static irqreturn_t lpuart_int(int irq, void *dev_id)
+ {
+       struct lpuart_port *sport = dev_id;
+-      unsigned char sts;
++      u8 sts;
+       sts = readb(sport->port.membase + UARTSR1);
+@@ -1113,7 +1113,7 @@ static void lpuart_copy_rx_to_tty(struct lpuart_port *sport)
+       int count, copied;
+       if (lpuart_is_32(sport)) {
+-              unsigned long sr = lpuart32_read(&sport->port, UARTSTAT);
++              u32 sr = lpuart32_read(&sport->port, UARTSTAT);
+               if (sr & (UARTSTAT_PE | UARTSTAT_FE)) {
+                       /* Clear the error flags */
+@@ -1125,10 +1125,10 @@ static void lpuart_copy_rx_to_tty(struct lpuart_port *sport)
+                               sport->port.icount.frame++;
+               }
+       } else {
+-              unsigned char sr = readb(sport->port.membase + UARTSR1);
++              u8 sr = readb(sport->port.membase + UARTSR1);
+               if (sr & (UARTSR1_PE | UARTSR1_FE)) {
+-                      unsigned char cr2;
++                      u8 cr2;
+                       /* Disable receiver during this operation... */
+                       cr2 = readb(sport->port.membase + UARTCR2);
+@@ -1279,7 +1279,7 @@ static void lpuart32_dma_idleint(struct lpuart_port *sport)
+ static irqreturn_t lpuart32_int(int irq, void *dev_id)
+ {
+       struct lpuart_port *sport = dev_id;
+-      unsigned long sts, rxcount;
++      u32 sts, rxcount;
+       sts = lpuart32_read(&sport->port, UARTSTAT);
+       rxcount = lpuart32_read(&sport->port, UARTWATER);
+@@ -1411,12 +1411,12 @@ static inline int lpuart_start_rx_dma(struct lpuart_port *sport)
+       dma_async_issue_pending(chan);
+       if (lpuart_is_32(sport)) {
+-              unsigned long temp = lpuart32_read(&sport->port, UARTBAUD);
++              u32 temp = lpuart32_read(&sport->port, UARTBAUD);
+               lpuart32_write(&sport->port, temp | UARTBAUD_RDMAE, UARTBAUD);
+               if (sport->dma_idle_int) {
+-                      unsigned long ctrl = lpuart32_read(&sport->port, UARTCTRL);
++                      u32 ctrl = lpuart32_read(&sport->port, UARTCTRL);
+                       lpuart32_write(&sport->port, ctrl | UARTCTRL_ILIE, UARTCTRL);
+               }
+@@ -1482,7 +1482,7 @@ static int lpuart32_config_rs485(struct uart_port *port, struct ktermios *termio
+       struct lpuart_port *sport = container_of(port,
+                       struct lpuart_port, port);
+-      unsigned long modem = lpuart32_read(&sport->port, UARTMODIR)
++      u32 modem = lpuart32_read(&sport->port, UARTMODIR)
+                               & ~(UARTMODIR_TXRTSPOL | UARTMODIR_TXRTSE);
+       u32 ctrl;
+@@ -1577,7 +1577,7 @@ static void lpuart32_set_mctrl(struct uart_port *port, unsigned int mctrl)
+ static void lpuart_break_ctl(struct uart_port *port, int break_state)
+ {
+-      unsigned char temp;
++      u8 temp;
+       temp = readb(port->membase + UARTCR2) & ~UARTCR2_SBK;
+@@ -1589,7 +1589,7 @@ static void lpuart_break_ctl(struct uart_port *port, int break_state)
+ static void lpuart32_break_ctl(struct uart_port *port, int break_state)
+ {
+-      unsigned long temp;
++      u32 temp;
+       temp = lpuart32_read(port, UARTCTRL);
+@@ -1623,8 +1623,7 @@ static void lpuart32_break_ctl(struct uart_port *port, int break_state)
+ static void lpuart_setup_watermark(struct lpuart_port *sport)
+ {
+-      unsigned char val, cr2;
+-      unsigned char cr2_saved;
++      u8 val, cr2, cr2_saved;
+       cr2 = readb(sport->port.membase + UARTCR2);
+       cr2_saved = cr2;
+@@ -1657,7 +1656,7 @@ static void lpuart_setup_watermark(struct lpuart_port *sport)
+ static void lpuart_setup_watermark_enable(struct lpuart_port *sport)
+ {
+-      unsigned char cr2;
++      u8 cr2;
+       lpuart_setup_watermark(sport);
+@@ -1668,8 +1667,7 @@ static void lpuart_setup_watermark_enable(struct lpuart_port *sport)
+ static void lpuart32_setup_watermark(struct lpuart_port *sport)
+ {
+-      unsigned long val, ctrl;
+-      unsigned long ctrl_saved;
++      u32 val, ctrl, ctrl_saved;
+       ctrl = lpuart32_read(&sport->port, UARTCTRL);
+       ctrl_saved = ctrl;
+@@ -1778,7 +1776,7 @@ static void lpuart_tx_dma_startup(struct lpuart_port *sport)
+ static void lpuart_rx_dma_startup(struct lpuart_port *sport)
+ {
+       int ret;
+-      unsigned char cr3;
++      u8 cr3;
+       if (uart_console(&sport->port))
+               goto err;
+@@ -1828,7 +1826,7 @@ static void lpuart_hw_setup(struct lpuart_port *sport)
+ static int lpuart_startup(struct uart_port *port)
+ {
+       struct lpuart_port *sport = container_of(port, struct lpuart_port, port);
+-      unsigned char temp;
++      u8 temp;
+       /* determine FIFO size and enable FIFO mode */
+       temp = readb(sport->port.membase + UARTPFIFO);
+@@ -1848,7 +1846,7 @@ static int lpuart_startup(struct uart_port *port)
+ static void lpuart32_hw_disable(struct lpuart_port *sport)
+ {
+-      unsigned long temp;
++      u32 temp;
+       temp = lpuart32_read(&sport->port, UARTCTRL);
+       temp &= ~(UARTCTRL_RIE | UARTCTRL_ILIE | UARTCTRL_RE |
+@@ -1858,7 +1856,7 @@ static void lpuart32_hw_disable(struct lpuart_port *sport)
+ static void lpuart32_configure(struct lpuart_port *sport)
+ {
+-      unsigned long temp;
++      u32 temp;
+       temp = lpuart32_read(&sport->port, UARTCTRL);
+       if (!sport->lpuart_dma_rx_use)
+@@ -1888,7 +1886,7 @@ static void lpuart32_hw_setup(struct lpuart_port *sport)
+ static int lpuart32_startup(struct uart_port *port)
+ {
+       struct lpuart_port *sport = container_of(port, struct lpuart_port, port);
+-      unsigned long temp;
++      u32 temp;
+       /* determine FIFO size */
+       temp = lpuart32_read(&sport->port, UARTFIFO);
+@@ -1942,7 +1940,7 @@ static void lpuart_dma_shutdown(struct lpuart_port *sport)
+ static void lpuart_shutdown(struct uart_port *port)
+ {
+       struct lpuart_port *sport = container_of(port, struct lpuart_port, port);
+-      unsigned char temp;
++      u8 temp;
+       unsigned long flags;
+       uart_port_lock_irqsave(port, &flags);
+@@ -1962,7 +1960,7 @@ static void lpuart32_shutdown(struct uart_port *port)
+ {
+       struct lpuart_port *sport =
+               container_of(port, struct lpuart_port, port);
+-      unsigned long temp;
++      u32 temp;
+       unsigned long flags;
+       uart_port_lock_irqsave(port, &flags);
+@@ -1993,7 +1991,7 @@ lpuart_set_termios(struct uart_port *port, struct ktermios *termios,
+ {
+       struct lpuart_port *sport = container_of(port, struct lpuart_port, port);
+       unsigned long flags;
+-      unsigned char cr1, old_cr1, old_cr2, cr3, cr4, bdh, modem;
++      u8 cr1, old_cr1, old_cr2, cr3, cr4, bdh, modem;
+       unsigned int  baud;
+       unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
+       unsigned int sbr, brfa;
+@@ -2231,7 +2229,7 @@ lpuart32_set_termios(struct uart_port *port, struct ktermios *termios,
+ {
+       struct lpuart_port *sport = container_of(port, struct lpuart_port, port);
+       unsigned long flags;
+-      unsigned long ctrl, old_ctrl, bd, modem;
++      u32 ctrl, old_ctrl, bd, modem;
+       unsigned int  baud;
+       unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
+@@ -2498,7 +2496,7 @@ static void
+ lpuart_console_write(struct console *co, const char *s, unsigned int count)
+ {
+       struct lpuart_port *sport = lpuart_ports[co->index];
+-      unsigned char  old_cr2, cr2;
++      u8  old_cr2, cr2;
+       unsigned long flags;
+       int locked = 1;
+@@ -2528,7 +2526,7 @@ static void
+ lpuart32_console_write(struct console *co, const char *s, unsigned int count)
+ {
+       struct lpuart_port *sport = lpuart_ports[co->index];
+-      unsigned long  old_cr, cr;
++      u32 old_cr, cr;
+       unsigned long flags;
+       int locked = 1;
+@@ -2562,7 +2560,7 @@ static void __init
+ lpuart_console_get_options(struct lpuart_port *sport, int *baud,
+                          int *parity, int *bits)
+ {
+-      unsigned char cr, bdh, bdl, brfa;
++      u8 cr, bdh, bdl, brfa;
+       unsigned int sbr, uartclk, baud_raw;
+       cr = readb(sport->port.membase + UARTCR2);
+@@ -2611,7 +2609,7 @@ static void __init
+ lpuart32_console_get_options(struct lpuart_port *sport, int *baud,
+                          int *parity, int *bits)
+ {
+-      unsigned long cr, bd;
++      u32 cr, bd;
+       unsigned int sbr, uartclk, baud_raw;
+       cr = lpuart32_read(&sport->port, UARTCTRL);
+@@ -2817,7 +2815,7 @@ static int lpuart_global_reset(struct lpuart_port *sport)
+ {
+       struct uart_port *port = &sport->port;
+       void __iomem *global_addr;
+-      unsigned long ctrl, bd;
++      u32 ctrl, bd;
+       unsigned int val = 0;
+       int ret;
+@@ -3023,7 +3021,7 @@ static int lpuart_runtime_resume(struct device *dev)
+ static void serial_lpuart_enable_wakeup(struct lpuart_port *sport, bool on)
+ {
+-      unsigned int val, baud;
++      u32 val, baud;
+       if (lpuart_is_32(sport)) {
+               val = lpuart32_read(&sport->port, UARTCTRL);
+@@ -3088,7 +3086,7 @@ static int lpuart_suspend_noirq(struct device *dev)
+ static int lpuart_resume_noirq(struct device *dev)
+ {
+       struct lpuart_port *sport = dev_get_drvdata(dev);
+-      unsigned int val;
++      u32 val;
+       pinctrl_pm_select_default_state(dev);
+@@ -3108,7 +3106,8 @@ static int lpuart_resume_noirq(struct device *dev)
+ static int lpuart_suspend(struct device *dev)
+ {
+       struct lpuart_port *sport = dev_get_drvdata(dev);
+-      unsigned long temp, flags;
++      u32 temp;
++      unsigned long flags;
+       uart_suspend_port(&lpuart_reg, &sport->port);
+-- 
+2.39.5
+
diff --git a/queue-6.13/tty-serial-lpuart-only-disable-cts-instead-of-overwr.patch b/queue-6.13/tty-serial-lpuart-only-disable-cts-instead-of-overwr.patch
new file mode 100644 (file)
index 0000000..93e95b7
--- /dev/null
@@ -0,0 +1,65 @@
+From 88670072fd9e9c3fd318afb72ffd3ebfe809814a Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Fri, 7 Mar 2025 14:54:46 +0800
+Subject: tty: serial: lpuart: only disable CTS instead of overwriting the
+ whole UARTMODIR register
+
+From: Sherry Sun <sherry.sun@nxp.com>
+
+[ Upstream commit e98ab45ec5182605d2e00114cba3bbf46b0ea27f ]
+
+No need to overwrite the whole UARTMODIR register before waiting the
+transmit engine complete, actually our target here is only to disable
+CTS flow control to avoid the dirty data in TX FIFO may block the
+transmit engine complete.
+Also delete the following duplicate CTS disable configuration.
+
+Fixes: d5a2e0834364 ("tty: serial: lpuart: disable flow control while waiting for the transmit engine to complete")
+Cc: stable <stable@kernel.org>
+Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
+Link: https://lore.kernel.org/r/20250307065446.1122482-1-sherry.sun@nxp.com
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ drivers/tty/serial/fsl_lpuart.c | 12 +++++++-----
+ 1 file changed, 7 insertions(+), 5 deletions(-)
+
+diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
+index 2971de64f6a3d..ca5beb0831153 100644
+--- a/drivers/tty/serial/fsl_lpuart.c
++++ b/drivers/tty/serial/fsl_lpuart.c
+@@ -2341,15 +2341,19 @@ lpuart32_set_termios(struct uart_port *port, struct ktermios *termios,
+       /* update the per-port timeout */
+       uart_update_timeout(port, termios->c_cflag, baud);
++      /*
++       * disable CTS to ensure the transmit engine is not blocked by the flow
++       * control when there is dirty data in TX FIFO
++       */
++      lpuart32_write(port, modem & ~UARTMODIR_TXCTSE, UARTMODIR);
++
+       /*
+        * LPUART Transmission Complete Flag may never be set while queuing a break
+        * character, so skip waiting for transmission complete when UARTCTRL_SBK is
+        * asserted.
+        */
+-      if (!(old_ctrl & UARTCTRL_SBK)) {
+-              lpuart32_write(port, 0, UARTMODIR);
++      if (!(old_ctrl & UARTCTRL_SBK))
+               lpuart32_wait_bit_set(port, UARTSTAT, UARTSTAT_TC);
+-      }
+       /* disable transmit and receive */
+       lpuart32_write(port, old_ctrl & ~(UARTCTRL_TE | UARTCTRL_RE),
+@@ -2357,8 +2361,6 @@ lpuart32_set_termios(struct uart_port *port, struct ktermios *termios,
+       lpuart32_write(port, bd, UARTBAUD);
+       lpuart32_serial_setbrg(sport, baud);
+-      /* disable CTS before enabling UARTCTRL_TE to avoid pending idle preamble */
+-      lpuart32_write(port, modem & ~UARTMODIR_TXCTSE, UARTMODIR);
+       /* restore control register */
+       lpuart32_write(port, ctrl, UARTCTRL);
+       /* re-enable the CTS if needed */
+-- 
+2.39.5
+