io: fix safety of LinkedList drain_filter API (#5832)

The `drain_filter` method on the internal `LinkedList` type passes a
`&mut` reference to the node type. However, the `LinkedList` is intended
to be used with nodes that are shared in other ways. For example
`task::Header` is accessible concurrently from multiple threads.

Currently, the only usage of `drain_filter` is in a case where `&mut`
access is safe, so this change is to help prevent future bugs and
tighten up the safety of internal utilities.
This commit is contained in:
Carl Lerche 2023-06-28 12:23:08 -07:00 committed by GitHub
parent 1bfe778acb
commit ec1f52e1d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -307,7 +307,7 @@ cfg_io_driver_impl! {
impl<T: Link> LinkedList<T, T::Target> { impl<T: Link> LinkedList<T, T::Target> {
pub(crate) fn drain_filter<F>(&mut self, filter: F) -> DrainFilter<'_, T, F> pub(crate) fn drain_filter<F>(&mut self, filter: F) -> DrainFilter<'_, T, F>
where where
F: FnMut(&mut T::Target) -> bool, F: FnMut(&T::Target) -> bool,
{ {
let curr = self.head; let curr = self.head;
DrainFilter { DrainFilter {
@ -321,7 +321,7 @@ cfg_io_driver_impl! {
impl<'a, T, F> Iterator for DrainFilter<'a, T, F> impl<'a, T, F> Iterator for DrainFilter<'a, T, F>
where where
T: Link, T: Link,
F: FnMut(&mut T::Target) -> bool, F: FnMut(&T::Target) -> bool,
{ {
type Item = T::Handle; type Item = T::Handle;