Skip to content

Commit

Permalink
astyle code formatting pass
Browse files Browse the repository at this point in the history
  • Loading branch information
slabasan committed Sep 23, 2024
1 parent 401b07f commit 4c270bc
Show file tree
Hide file tree
Showing 9 changed files with 262 additions and 156 deletions.
1 change: 0 additions & 1 deletion examples/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*
*/


#include <stdio.h> // printf(3)
#include <assert.h> // assert(3)
#include <fcntl.h> // open(2)
Expand Down
41 changes: 23 additions & 18 deletions msr_allowlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ static void delete_allowlist(void);
static int create_allowlist(int nentries);
static struct allowlist_entry *find_in_allowlist(u64 msr);
static void add_to_allowlist(struct allowlist_entry *entry);
static int parse_next_allowlist_entry(char *inbuf, char **nextinbuf, struct allowlist_entry *entry);
static ssize_t read_allowlist(struct file *file, char __user *buf, size_t count, loff_t *ppos);
static int parse_next_allowlist_entry(char *inbuf, char **nextinbuf,
struct allowlist_entry *entry);
static ssize_t read_allowlist(struct file *file, char __user *buf, size_t count,
loff_t *ppos);
static struct class *cdev_class;
static char cdev_created;
static char cdev_registered;
Expand Down Expand Up @@ -85,7 +87,8 @@ static int open_allowlist(struct inode *inode, struct file *file)
* valid, we will then delete the current white list and then perform the
* second pass to actually create the new white list.
*/
static ssize_t write_allowlist(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
static ssize_t write_allowlist(struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
{
int err = 0;
const u32 __user *tmp = (const u32 __user *)buf;
Expand All @@ -105,16 +108,16 @@ static ssize_t write_allowlist(struct file *file, const char __user *buf, size_t
return count;
}

if (count+1 > MAX_WLIST_BSIZE)
if (count + 1 > MAX_WLIST_BSIZE)
{
pr_err("%s: buffer of %zu bytes too large\n", __FUNCTION__, count);
return -E2BIG;
}

kbuf = kzalloc(count+1, GFP_KERNEL);
kbuf = kzalloc(count + 1, GFP_KERNEL);
if (ZERO_OR_NULL_PTR(kbuf))
{
pr_err("%s: memory alloc(%zu) failed\n", __FUNCTION__, count+1);
pr_err("%s: memory alloc(%zu) failed\n", __FUNCTION__, count + 1);
return -ENOMEM;
}

Expand All @@ -126,7 +129,7 @@ static ssize_t write_allowlist(struct file *file, const char __user *buf, size_t
}

/* Pass 1: */
for (num_entries = 0, s = kbuf, res = 1; res > 0; )
for (num_entries = 0, s = kbuf, res = 1; res > 0;)
{
res = parse_next_allowlist_entry(s, &s, 0);
if (res < 0)
Expand All @@ -144,7 +147,8 @@ static ssize_t write_allowlist(struct file *file, const char __user *buf, size_t

if (num_entries == 0)
{
pr_err("%s: No valid entries found in %zu bytes of input\n", __FUNCTION__, count);
pr_err("%s: No valid entries found in %zu bytes of input\n", __FUNCTION__,
count);
err = -ENOMSG;
goto out_freebuffer;
}
Expand Down Expand Up @@ -190,7 +194,8 @@ static ssize_t write_allowlist(struct file *file, const char __user *buf, size_t
return err ? err : count;
}

static ssize_t read_allowlist(struct file *file, char __user *buf, size_t count, loff_t *ppos)
static ssize_t read_allowlist(struct file *file, char __user *buf, size_t count,
loff_t *ppos)
{
loff_t idx = *ppos;
u32 __user *tmp = (u32 __user *) buf;
Expand All @@ -212,14 +217,14 @@ static ssize_t read_allowlist(struct file *file, char __user *buf, size_t count,

if (idx == 0)
{
len = sprintf(kbuf, "%-10s %-18s\n" "0x%08llX 0x%016llX\n", "#MSR", "Write mask", e.msr, e.wmask);
len = sprintf(kbuf, "%-10s %-18s\n" "0x%08llX 0x%016llX\n", "#MSR",
"Write mask", e.msr, e.wmask);
}
else
{
len = sprintf(kbuf, "0x%08llX 0x%016llX\n", e.msr, e.wmask);
}


if (len > count)
{
return -E2BIG;
Expand All @@ -230,7 +235,7 @@ static ssize_t read_allowlist(struct file *file, char __user *buf, size_t count,
return -EFAULT;
}

*ppos = idx+1;
*ppos = idx + 1;
return len;
}

Expand Down Expand Up @@ -295,13 +300,13 @@ static struct allowlist_entry *find_in_allowlist(u64 msr)
return 0;
}


static void add_to_allowlist(struct allowlist_entry *entry)
{
hash_add(allowlist_hash, &entry->hlist, entry->msr);
}

static int parse_next_allowlist_entry(char *inbuf, char **nextinbuf, struct allowlist_entry *entry)
static int parse_next_allowlist_entry(char *inbuf, char **nextinbuf,
struct allowlist_entry *entry)
{
char *s = skip_spaces(inbuf);
int i;
Expand Down Expand Up @@ -361,7 +366,6 @@ static int parse_next_allowlist_entry(char *inbuf, char **nextinbuf, struct allo
return *nextinbuf - inbuf;
}


#define msr_allowlist_nodename_selector _Generic(\
(((struct class *)0)->devnode),\
char* (*) (struct device *, mode_t *) : msr_allowlist_nodename1,\
Expand Down Expand Up @@ -428,9 +432,9 @@ int msr_allowlist_init(int *majordev)

cdev_class = class_create(
#if LINUX_VERSION_CODE < KERNEL_VERSION(6,4,0)
THIS_MODULE,
THIS_MODULE,
#endif
"msr_allowlist");
"msr_allowlist");
if (IS_ERR(cdev_class))
{
err = PTR_ERR(cdev_class);
Expand All @@ -441,7 +445,8 @@ int msr_allowlist_init(int *majordev)

cdev_class->devnode = msr_allowlist_nodename_selector;

dev = device_create(cdev_class, NULL, MKDEV(*majordev, 0), NULL, "msr_allowlist");
dev = device_create(cdev_class, NULL, MKDEV(*majordev, 0), NULL,
"msr_allowlist");
if (IS_ERR(dev))
{
err = PTR_ERR(dev);
Expand Down
4 changes: 2 additions & 2 deletions msr_batch.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ int msrbatch_init(int *majordev)

cdev_class = class_create(
#if LINUX_VERSION_CODE < KERNEL_VERSION(6,4,0)
THIS_MODULE,
THIS_MODULE,
#endif
"msr_batch");
"msr_batch");
if (IS_ERR(cdev_class))
{
err = PTR_ERR(cdev_class);
Expand Down
20 changes: 13 additions & 7 deletions msr_entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ static loff_t msr_seek(struct file *file, loff_t offset, int orig)
return ret;
}

static ssize_t msr_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
static ssize_t msr_read(struct file *file, char __user *buf, size_t count,
loff_t *ppos)
{
u32 __user *tmp = (u32 __user *) buf;
u32 data[2];
Expand Down Expand Up @@ -126,7 +127,8 @@ static ssize_t msr_read(struct file *file, char __user *buf, size_t count, loff_
return 8;
}

static ssize_t msr_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
static ssize_t msr_write(struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
{
const u32 __user *tmp = (const u32 __user *)buf;
u32 curdata[2];
Expand All @@ -138,7 +140,7 @@ static ssize_t msr_write(struct file *file, const char __user *buf, size_t count

if (count != 8) /* single write only */
{
return -EINVAL;
return -EINVAL;
}

mask = msr_allowlist_writemask(reg);
Expand Down Expand Up @@ -211,7 +213,8 @@ static int msr_device_create(unsigned int cpu)
{
struct device *dev;

dev = device_create(msr_class, NULL, MKDEV(mdev_msr_safe, cpu), NULL, "msr_safe%d", cpu);
dev = device_create(msr_class, NULL, MKDEV(mdev_msr_safe, cpu), NULL,
"msr_safe%d", cpu);
return IS_ERR(dev) ? PTR_ERR(dev) : 0;
}

Expand All @@ -229,7 +232,8 @@ static int msr_device_destroy(unsigned int cpu)
#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(4,10,0)
static int msr_class_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
static int msr_class_cpu_callback(struct notifier_block *nfb,
unsigned long action, void *hcpu)
{
unsigned int cpu = (unsigned long)hcpu;
int err = 0;
Expand Down Expand Up @@ -317,7 +321,8 @@ static int __init msr_init(void)
* number and return zero on success
* Return a negative errno on failure
*/
err = __register_chrdev(mdev_msr_safe, 0, num_possible_cpus(), "cpu/msr_safe", &msr_fops);
err = __register_chrdev(mdev_msr_safe, 0, num_possible_cpus(), "cpu/msr_safe",
&msr_fops);
if (err < 0)
{
pr_debug("unable to get major %d for msr_safe\n", mdev_msr_safe);
Expand Down Expand Up @@ -356,7 +361,8 @@ static int __init msr_init(void)
}
register_hotcpu_notifier(&msr_class_cpu_notifier);
#else
err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/msr:online", msr_device_create, msr_device_destroy);
err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/msr:online",
msr_device_create, msr_device_destroy);
if (err < 0)
{
goto out_class;
Expand Down
16 changes: 9 additions & 7 deletions msr_version.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ static int open_version(struct inode *inode, struct file *file)
return 0;
}

static ssize_t read_version(struct file *file, char __user *buf, size_t count, loff_t *ppos)
static ssize_t read_version(struct file *file, char __user *buf, size_t count,
loff_t *ppos)
{
size_t len = strlen( THIS_MODULE->version ) + 1 < count ?
strlen( THIS_MODULE->version ) + 1 :
count;
size_t len = strlen(THIS_MODULE->version) + 1 < count ?
strlen(THIS_MODULE->version) + 1 :
count;
if (*ppos > 0)
{
return 0;
Expand Down Expand Up @@ -128,9 +129,9 @@ int msr_version_init(int *majordev)

cdev_class = class_create(
#if LINUX_VERSION_CODE < KERNEL_VERSION(6,4,0)
THIS_MODULE,
THIS_MODULE,
#endif
"msr_safe_version");
"msr_safe_version");
if (IS_ERR(cdev_class))
{
err = PTR_ERR(cdev_class);
Expand All @@ -141,7 +142,8 @@ int msr_version_init(int *majordev)

cdev_class->devnode = msr_version_nodename_selector;

dev = device_create(cdev_class, NULL, MKDEV(*majordev, 0), NULL, "msr_safe_version");
dev = device_create(cdev_class, NULL, MKDEV(*majordev, 0), NULL,
"msr_safe_version");
if (IS_ERR(dev))
{
err = PTR_ERR(dev);
Expand Down
Loading

0 comments on commit 4c270bc

Please sign in to comment.