[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20240424122533.79720-1-andrea.calabrese@amarulasolutions.com>
Date: Wed, 24 Apr 2024 14:25:33 +0200
From: Andrea Calabrese <andrea.calabrese@...rulasolutions.com>
To: linux-kernel@...r.kernel.org
Cc: trivial@...nel.org,
Andrea Calabrese <andrea.calabrese@...rulasolutions.com>
Subject: [PATCH] map.c: refactoring magic constant
In map.c there is a magic constant of value 255 for the maximum number
of probes. It is in many places in the code, in this commit I modified
it to make it more clear
Signed-off-by: Andrea Calabrese <andrea.calabrese@...rulasolutions.com>
---
drivers/base/map.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/drivers/base/map.c b/drivers/base/map.c
index 83aeb09ca161..b27f0cf557f4 100644
--- a/drivers/base/map.c
+++ b/drivers/base/map.c
@@ -16,6 +16,8 @@
#include <linux/kobject.h>
#include <linux/kobj_map.h>
+#define MAX_PROBES = 255
+
struct kobj_map {
struct probe {
struct probe *next;
@@ -25,7 +27,7 @@ struct kobj_map {
kobj_probe_t *get;
int (*lock)(dev_t, void *);
void *data;
- } *probes[255];
+ } *probes[MAX_PROBES];
struct mutex *lock;
};
@@ -38,8 +40,8 @@ int kobj_map(struct kobj_map *domain, dev_t dev, unsigned long range,
unsigned int i;
struct probe *p;
- if (n > 255)
- n = 255;
+ if (n > MAX_PROBES)
+ n = MAX_PROBES;
p = kmalloc_array(n, sizeof(struct probe), GFP_KERNEL);
if (p == NULL)
@@ -55,7 +57,7 @@ int kobj_map(struct kobj_map *domain, dev_t dev, unsigned long range,
}
mutex_lock(domain->lock);
for (i = 0, p -= n; i < n; i++, p++, index++) {
- struct probe **s = &domain->probes[index % 255];
+ struct probe **s = &domain->probes[index % MAX_PROBES];
while (*s && (*s)->range < range)
s = &(*s)->next;
p->next = *s;
@@ -72,13 +74,13 @@ void kobj_unmap(struct kobj_map *domain, dev_t dev, unsigned long range)
unsigned int i;
struct probe *found = NULL;
- if (n > 255)
- n = 255;
+ if (n > MAX_PROBES)
+ n = MAX_PROBES;
mutex_lock(domain->lock);
for (i = 0; i < n; i++, index++) {
struct probe **s;
- for (s = &domain->probes[index % 255]; *s; s = &(*s)->next) {
+ for (s = &domain->probes[index % MAX_PROBES]; *s; s = &(*s)->next) {
struct probe *p = *s;
if (p->dev == dev && p->range == range) {
*s = p->next;
@@ -100,7 +102,7 @@ struct kobject *kobj_lookup(struct kobj_map *domain, dev_t dev, int *index)
retry:
mutex_lock(domain->lock);
- for (p = domain->probes[MAJOR(dev) % 255]; p; p = p->next) {
+ for (p = domain->probes[MAJOR(dev) % MAX_PROBES]; p; p = p->next) {
struct kobject *(*probe)(dev_t, int *, void *);
struct module *owner;
void *data;
@@ -147,7 +149,7 @@ struct kobj_map *kobj_map_init(kobj_probe_t *base_probe, struct mutex *lock)
base->dev = 1;
base->range = ~0;
base->get = base_probe;
- for (i = 0; i < 255; i++)
+ for (i = 0; i < MAX_PROBES; i++)
p->probes[i] = base;
p->lock = lock;
return p;
--
2.34.1
Powered by blists - more mailing lists