News for hackers. Stuff that matters.
Re:Rust support in the Linux kernel by estebank on Thursday December 09, 2021 @01:07PM (#29500814)
The posted code isn't terrible, but it is a bit denser and harder to read than I'd like. Some small changes (like importing the macros to avoid a full path) makes a bit easier to read

        // SAFETY: This device doesn't support DMA.
        let base = unsafe { IoMem::try_new(res)? };

        let mut data = new_device_data!(
            RegistrationWithIrqChip::new(),
            PL061Resources { base, parent_irq: irq },
            // SAFETY: We call `spinlock_init` below.
            unsafe { SpinLock::new(PL061Data::default()) },
            "PL061::Registrations"
        )?;

        // SAFETY: General part of the data is pinned when `data` is.
        let gen = unsafe { data.as_mut().map_unchecked_mut(|d| &mut **d) };
        spinlock_init!(gen, "PL061::General");

        let data: Ref<DeviceData> = data.into();
I imagine code like this would be the body of a small function that does all this unsafe preparations and gives back a Result<Ref<DeviceData>, Error> once it's done, which would change the end to be

        Ok(data.into())
Re:Rust support in the Linux kernel by ggrrhh_ta on Thursday December 09, 2021 @03:44PM (#29502675)
Thanks, it actually looks better and more understandable.