Due to asynchronous driver probing there is a chance that the dummy
regulator hasn't already been probed when first accessing it.
Cc: stable(a)vger.kernel.org
Signed-off-by: Christian Eggers <ceggers(a)arri.de>
---
v2:
- return -EPROBE_DEFER rather than using BUG_ON()
v3:
- move dev_warn() below returning -EPROBE_DEFER
drivers/regulator/core.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 4ddf0efead68..4d0f13899e6b 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -2069,6 +2069,10 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
if (have_full_constraints()) {
r = dummy_regulator_rdev;
+ if (!r) {
+ ret = -EPROBE_DEFER;
+ goto out;
+ }
get_device(&r->dev);
} else {
dev_err(dev, "Failed to resolve %s-supply for %s\n",
@@ -2086,6 +2090,10 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
goto out;
}
r = dummy_regulator_rdev;
+ if (!r) {
+ ret = -EPROBE_DEFER;
+ goto out;
+ }
get_device(&r->dev);
}
@@ -2211,8 +2219,10 @@ struct regulator *_regulator_get_common(struct regulator_dev *rdev, struct devic
* enabled, even if it isn't hooked up, and just
* provide a dummy.
*/
- dev_warn(dev, "supply %s not found, using dummy regulator\n", id);
rdev = dummy_regulator_rdev;
+ if (!rdev)
+ return ERR_PTR(-EPROBE_DEFER);
+ dev_warn(dev, "supply %s not found, using dummy regulator\n", id);
get_device(&rdev->dev);
break;
--
2.44.1
The vfio_ap_mdev_request function in drivers/s390/crypto/vfio_ap_ops.c
accesses fields of an ap_matrix_mdev object without ensuring that the
object is accessed by only one thread at a time. This patch adds the lock
necessary to secure access to the ap_matrix_mdev object.
Fixes: 2e3d8d71e285 ("s390/vfio-ap: wire in the vfio_device_ops request callback")
Signed-off-by: Anthony Krowiak <akrowiak(a)linux.ibm.com>
Cc: <stable(a)vger.kernel.org>
---
drivers/s390/crypto/vfio_ap_ops.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c
index a52c2690933f..a2784d3357d9 100644
--- a/drivers/s390/crypto/vfio_ap_ops.c
+++ b/drivers/s390/crypto/vfio_ap_ops.c
@@ -2045,6 +2045,7 @@ static void vfio_ap_mdev_request(struct vfio_device *vdev, unsigned int count)
struct ap_matrix_mdev *matrix_mdev;
matrix_mdev = container_of(vdev, struct ap_matrix_mdev, vdev);
+ mutex_lock(&matrix_dev->mdevs_lock);
if (matrix_mdev->req_trigger) {
if (!(count % 10))
@@ -2057,6 +2058,8 @@ static void vfio_ap_mdev_request(struct vfio_device *vdev, unsigned int count)
dev_notice(dev,
"No device request registered, blocked until released by user\n");
}
+
+ mutex_unlock(&matrix_dev->mdevs_lock);
}
static int vfio_ap_mdev_get_device_info(unsigned long arg)
--
2.47.1
Hi Greg, Sasha,
Please consider this series for 6.12.y. It should apply cleanly on top
of v6.12.18.
These are the patches to backport the `alloc` series for Rust, which
will be useful for Rust Android Binder and others. It also means that,
with this applied, we will not rely on the standard library `alloc` (and
the unstable `cfg` option we used) anymore in any stable kernel that
supports several Rust versions, so e.g. upstream Rust could consider
removing that `cfg` if they needed.
The entire series of cherry-picks apply almost cleanly (only 2 trivial
conflicts) -- to achieve that, I included the `#[expect]` support, which
will make future backports that use that feature easier anyway. That
series also enabled some Clippy warnings. We could reduce the series,
but the end result is warning-free and Clippy is opt-in anyway.
Out-of-tree code could, of course, see some warnings if they use it.
I also included a bunch of Clippy warnings cleanups for the DRM QR Code
to have this series clean up to Rust 1.85.0 (the latest stable), but
I could send them separately if needed.
Finally, I included the "Custom FFI" series backport, which in turn
solves the arm64 + Rust 1.85.0 + `CONFIG_RUST_FW_LOADER_ABSTRACTIONS=y`
issue. It will also make future patches easier to backport, since we
will have the same `ffi::` types.
I tested that the entire series builds between every commit for x86_64
`LLVM=1` with the latest stable and minimum supported Rust compiler
versions. I also ran my usual stable kernel tests on the end result;
that is, boot-tested in QEMU for several architectures etc. In v6.12.18
for loongarch there is an unrelated error that was not there in v6.12.17
when I did a previous test run -- reported separately.
Things could still break, so extra tests on the next -rc from users in
Cc here would be welcome -- thanks!
Cheers,
Miguel
Asahi Lina (1):
rust: alloc: Fix `ArrayLayout` allocations
Benno Lossin (1):
rust: alloc: introduce `ArrayLayout`
Danilo Krummrich (28):
rust: alloc: add `Allocator` trait
rust: alloc: separate `aligned_size` from `krealloc_aligned`
rust: alloc: rename `KernelAllocator` to `Kmalloc`
rust: alloc: implement `ReallocFunc`
rust: alloc: make `allocator` module public
rust: alloc: implement `Allocator` for `Kmalloc`
rust: alloc: add module `allocator_test`
rust: alloc: implement `Vmalloc` allocator
rust: alloc: implement `KVmalloc` allocator
rust: alloc: add __GFP_NOWARN to `Flags`
rust: alloc: implement kernel `Box`
rust: treewide: switch to our kernel `Box` type
rust: alloc: remove extension of std's `Box`
rust: alloc: add `Box` to prelude
rust: alloc: implement kernel `Vec` type
rust: alloc: implement `IntoIterator` for `Vec`
rust: alloc: implement `collect` for `IntoIter`
rust: treewide: switch to the kernel `Vec` type
rust: alloc: remove `VecExt` extension
rust: alloc: add `Vec` to prelude
rust: error: use `core::alloc::LayoutError`
rust: error: check for config `test` in `Error::name`
rust: alloc: implement `contains` for `Flags`
rust: alloc: implement `Cmalloc` in module allocator_test
rust: str: test: replace `alloc::format`
rust: alloc: update module comment of alloc.rs
kbuild: rust: remove the `alloc` crate and `GlobalAlloc`
MAINTAINERS: add entry for the Rust `alloc` module
Ethan D. Twardy (1):
rust: kbuild: expand rusttest target for macros
Filipe Xavier (2):
rust: error: make conversion functions public
rust: error: optimize error type to use nonzero
Gary Guo (3):
rust: fix size_t in bindgen prototypes of C builtins
rust: map `__kernel_size_t` and friends also to usize/isize
rust: use custom FFI integer types
Miguel Ojeda (17):
rust: workqueue: remove unneeded ``#[allow(clippy::new_ret_no_self)]`
rust: sort global Rust flags
rust: types: avoid repetition in `{As,From}Bytes` impls
rust: enable `clippy::undocumented_unsafe_blocks` lint
rust: enable `clippy::unnecessary_safety_comment` lint
rust: enable `clippy::unnecessary_safety_doc` lint
rust: enable `clippy::ignored_unit_patterns` lint
rust: enable `rustdoc::unescaped_backticks` lint
rust: init: remove unneeded `#[allow(clippy::disallowed_names)]`
rust: sync: remove unneeded
`#[allow(clippy::non_send_fields_in_send_ty)]`
rust: introduce `.clippy.toml`
rust: replace `clippy::dbg_macro` with `disallowed_macros`
rust: provide proper code documentation titles
rust: enable Clippy's `check-private-items`
Documentation: rust: add coding guidelines on lints
rust: start using the `#[expect(...)]` attribute
Documentation: rust: discuss `#[expect(...)]` in the guidelines
Thomas Böhler (7):
drm/panic: avoid reimplementing Iterator::find
drm/panic: remove unnecessary borrow in alignment_pattern
drm/panic: prefer eliding lifetimes
drm/panic: remove redundant field when assigning value
drm/panic: correctly indent continuation of line in list item
drm/panic: allow verbose boolean for clarity
drm/panic: allow verbose version check
.clippy.toml | 9 +
.gitignore | 1 +
Documentation/rust/coding-guidelines.rst | 148 ++++
MAINTAINERS | 8 +
Makefile | 15 +-
drivers/block/rnull.rs | 4 +-
drivers/gpu/drm/drm_panic_qr.rs | 23 +-
mm/kasan/kasan_test_rust.rs | 3 +-
rust/Makefile | 92 +--
rust/bindgen_parameters | 5 +
rust/bindings/bindings_helper.h | 1 +
rust/bindings/lib.rs | 6 +
rust/exports.c | 1 -
rust/ffi.rs | 13 +
rust/helpers/helpers.c | 1 +
rust/helpers/slab.c | 6 +
rust/helpers/vmalloc.c | 9 +
rust/kernel/alloc.rs | 150 +++-
rust/kernel/alloc/allocator.rs | 208 ++++--
rust/kernel/alloc/allocator_test.rs | 95 +++
rust/kernel/alloc/box_ext.rs | 89 ---
rust/kernel/alloc/kbox.rs | 456 +++++++++++
rust/kernel/alloc/kvec.rs | 913 +++++++++++++++++++++++
rust/kernel/alloc/layout.rs | 91 +++
rust/kernel/alloc/vec_ext.rs | 185 -----
rust/kernel/block/mq/operations.rs | 18 +-
rust/kernel/block/mq/raw_writer.rs | 2 +-
rust/kernel/block/mq/tag_set.rs | 2 +-
rust/kernel/error.rs | 79 +-
rust/kernel/init.rs | 127 ++--
rust/kernel/init/__internal.rs | 13 +-
rust/kernel/init/macros.rs | 18 +-
rust/kernel/ioctl.rs | 2 +-
rust/kernel/lib.rs | 5 +-
rust/kernel/list.rs | 1 +
rust/kernel/list/arc_field.rs | 2 +-
rust/kernel/net/phy.rs | 16 +-
rust/kernel/prelude.rs | 5 +-
rust/kernel/print.rs | 5 +-
rust/kernel/rbtree.rs | 49 +-
rust/kernel/std_vendor.rs | 12 +-
rust/kernel/str.rs | 46 +-
rust/kernel/sync/arc.rs | 25 +-
rust/kernel/sync/arc/std_vendor.rs | 2 +
rust/kernel/sync/condvar.rs | 7 +-
rust/kernel/sync/lock.rs | 8 +-
rust/kernel/sync/lock/mutex.rs | 4 +-
rust/kernel/sync/lock/spinlock.rs | 4 +-
rust/kernel/sync/locked_by.rs | 2 +-
rust/kernel/task.rs | 8 +-
rust/kernel/time.rs | 4 +-
rust/kernel/types.rs | 140 ++--
rust/kernel/uaccess.rs | 23 +-
rust/kernel/workqueue.rs | 29 +-
rust/macros/lib.rs | 14 +-
rust/macros/module.rs | 8 +-
rust/uapi/lib.rs | 6 +
samples/rust/rust_minimal.rs | 4 +-
samples/rust/rust_print.rs | 1 +
scripts/Makefile.build | 4 +-
scripts/generate_rust_analyzer.py | 11 +-
61 files changed, 2482 insertions(+), 756 deletions(-)
create mode 100644 .clippy.toml
create mode 100644 rust/ffi.rs
create mode 100644 rust/helpers/vmalloc.c
create mode 100644 rust/kernel/alloc/allocator_test.rs
delete mode 100644 rust/kernel/alloc/box_ext.rs
create mode 100644 rust/kernel/alloc/kbox.rs
create mode 100644 rust/kernel/alloc/kvec.rs
create mode 100644 rust/kernel/alloc/layout.rs
delete mode 100644 rust/kernel/alloc/vec_ext.rs
--
2.48.1
Sometimes I get a NULL pointer dereference at boot time in kobject_get()
with the following call stack:
anatop_regulator_probe()
devm_regulator_register()
regulator_register()
regulator_resolve_supply()
kobject_get()
By placing some extra BUG_ON() statements I could verify that this is
raised because probing of the 'dummy' regulator driver is not completed
('dummy_regulator_rdev' is still NULL).
In the JTAG debugger I can see that dummy_regulator_probe() and
anatop_regulator_probe() can be run by different kernel threads
(kworker/u4:*). I haven't further investigated whether this can be
changed or if there are other possibilities to force synchronization
between these two probe routines. On the other hand I don't expect much
boot time penalty by probing the 'dummy' regulator synchronously.
Cc: stable(a)vger.kernel.org
Fixes: 259b93b21a9f ("regulator: Set PROBE_PREFER_ASYNCHRONOUS for drivers that existed in 4.14")
Signed-off-by: Christian Eggers <ceggers(a)arri.de>
---
v2:
- no changes
v3:
- no changes
drivers/regulator/dummy.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/regulator/dummy.c b/drivers/regulator/dummy.c
index 5b9b9e4e762d..9f59889129ab 100644
--- a/drivers/regulator/dummy.c
+++ b/drivers/regulator/dummy.c
@@ -60,7 +60,7 @@ static struct platform_driver dummy_regulator_driver = {
.probe = dummy_regulator_probe,
.driver = {
.name = "reg-dummy",
- .probe_type = PROBE_PREFER_ASYNCHRONOUS,
+ .probe_type = PROBE_FORCE_SYNCHRONOUS,
},
};
--
2.44.1
Once device_register() failed, we should call put_device() to
decrement reference count for cleanup. Or it could cause memory leak.
As comment of device_register() says, 'NOTE: _Never_ directly free
@dev after calling this function, even if it returned an error! Always
use put_device() to give up the reference initialized in this function
instead.'
Found by code review.
Cc: stable(a)vger.kernel.org
Fixes: baa057e29b58 ("media: v4l2-dev: use pr_foo() for printing messages")
Signed-off-by: Ma Ke <make24(a)iscas.ac.cn>
---
drivers/media/v4l2-core/v4l2-dev.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c
index 5bcaeeba4d09..1619614e96bf 100644
--- a/drivers/media/v4l2-core/v4l2-dev.c
+++ b/drivers/media/v4l2-core/v4l2-dev.c
@@ -1060,6 +1060,7 @@ int __video_register_device(struct video_device *vdev,
if (ret < 0) {
mutex_unlock(&videodev_lock);
pr_err("%s: device_register failed\n", __func__);
+ put_device(&vdev->dev);
goto cleanup;
}
/* Register the release callback that will be called when the last
--
2.25.1
Once device_add() failed, we should call put_device() to decrement
reference count for cleanup. Or it could cause memory leak.
As comment of device_add() says, 'if device_add() succeeds, you should
call device_del() when you want to get rid of it. If device_add() has
not succeeded, use only put_device() to drop the reference count'.
Found by code review.
Cc: stable(a)vger.kernel.org
Fixes: 8434aa8b6fe5 ("[SCSI] iscsi: break up session creation into two stages")
Signed-off-by: Ma Ke <make24(a)iscas.ac.cn>
---
drivers/scsi/scsi_transport_iscsi.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
index 9c347c64c315..74333e182612 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -2114,6 +2114,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
release_dev:
device_del(&session->dev);
release_ida:
+ put_device(&session->dev);
if (session->ida_used)
ida_free(&iscsi_sess_ida, session->target_id);
destroy_wq:
--
2.25.1
Once device_add() failed, we should call put_device() to decrement
reference count for cleanup. Or it could cause memory leak.
As comment of device_add() says, 'if device_add() succeeds, you should
call device_del() when you want to get rid of it. If device_add() has
not succeeded, use only put_device() to drop the reference count'.
Found by code review.
Cc: stable(a)vger.kernel.org
Fixes: 54506918059a ("Bluetooth: Move SMP initialization after HCI init")
Signed-off-by: Ma Ke <make24(a)iscas.ac.cn>
---
net/bluetooth/hci_core.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index e7ec12437c8b..c03fd16d3c46 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -2641,6 +2641,7 @@ int hci_register_dev(struct hci_dev *hdev)
return id;
err_wqueue:
+ put_device(&hdev->dev);
debugfs_remove_recursive(hdev->debugfs);
destroy_workqueue(hdev->workqueue);
destroy_workqueue(hdev->req_workqueue);
--
2.25.1
Once device_add() failed, we should call put_device() to decrement
reference count for cleanup. Or it could cause memory leak.
As comment of device_add() says, 'if device_add() succeeds, you should
call device_del() when you want to get rid of it. If device_add() has
not succeeded, use only put_device() to drop the reference count'.
Found by code review.
Cc: stable(a)vger.kernel.org
Fixes: 0cd587735205 ("Input: preallocate memory to hold event values")
Signed-off-by: Ma Ke <make24(a)iscas.ac.cn>
---
drivers/input/input.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/input/input.c b/drivers/input/input.c
index c9e3ac64bcd0..2e70f346dadc 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -2424,6 +2424,7 @@ int input_register_device(struct input_dev *dev)
err_device_del:
device_del(&dev->dev);
err_devres_free:
+ put_device(&dev->dev);
devres_free(devres);
return error;
}
--
2.25.1
Once device_add() failed, we should call put_device() to decrement
reference count for cleanup. Or it could cause memory leak.
As comment of device_add() says, 'if device_add() succeeds, you should
call device_del() when you want to get rid of it. If device_add() has
not succeeded, use only put_device() to drop the reference count'.
Found by code review.
Cc: stable(a)vger.kernel.org
Fixes: 8ed633b9baf9 ("Revert "net-sysfs: Fix memory leak in netdev_register_kobject"")
Signed-off-by: Ma Ke <make24(a)iscas.ac.cn>
---
net/core/net-sysfs.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 07cb99b114bd..f443eacc9237 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -2169,6 +2169,7 @@ int netdev_register_kobject(struct net_device *ndev)
error = device_add(dev);
if (error)
+ put_device(dev);
return error;
error = register_queue_kobjects(ndev);
--
2.25.1