Skip to content
This repository has been archived by the owner on Mar 7, 2021. It is now read-only.

Commit

Permalink
Get rid of the reference type
Browse files Browse the repository at this point in the history
  • Loading branch information
geofft committed Aug 19, 2019
1 parent d901d64 commit 386601d
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions tests/json-sysctl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,9 @@ use core::convert::TryInto;
use serde::Serialize;
use serde_json_core;

use linux_kernel_module::sysctl::{Sysctl, SysctlStorage};
use linux_kernel_module::sysctl::Sysctl;
use linux_kernel_module::Mode;
use linux_kernel_module::error;
use linux_kernel_module::println;
use linux_kernel_module::user_ptr::UserSlicePtrWriter;

struct Reference(&'static AtomicBool);

impl SysctlStorage for Reference {
fn store_value(&self, data: &[u8]) -> (usize, error::KernelResult<()>) {
self.0.store_value(&*data)
}
fn read_value(&self, data: &mut UserSlicePtrWriter) -> (usize, error::KernelResult<()>) {
self.0.read_value(&mut *data)
}
}

static A: AtomicBool = AtomicBool::new(false);
static B: AtomicBool = AtomicBool::new(false);
Expand Down Expand Up @@ -56,9 +43,9 @@ impl linux_kernel_module::chrdev::FileOperations for JsonChrdev {
}

struct JsonSysctlModule {
_a: Sysctl<Reference>,
_b: Sysctl<Reference>,
_c: Sysctl<Reference>,
_a: Sysctl<&'static AtomicBool>,
_b: Sysctl<&'static AtomicBool>,
_c: Sysctl<&'static AtomicBool>,
_chrdev_registration: linux_kernel_module::chrdev::Registration,
}

Expand All @@ -78,19 +65,19 @@ impl linux_kernel_module::KernelModule for JsonSysctlModule {
_a: Sysctl::register(
"json-sysctl\x00",
"a\x00",
Reference(&A),
&A,
Mode::from_int(0o666),
)?,
_b: Sysctl::register(
"json-sysctl\x00",
"b\x00",
Reference(&B),
&B,
Mode::from_int(0o666),
)?,
_c: Sysctl::register(
"json-sysctl\x00",
"c\x00",
Reference(&C),
&C,
Mode::from_int(0o666),
)?,
_chrdev_registration: chrdev_registration,
Expand Down

0 comments on commit 386601d

Please sign in to comment.