[RFC PATCH 36/39] parport: move device sysctl context to priv
From: wen . yang
Date: Wed Oct 28 2026 - 12:47:28 EST
From: Wen Yang <wen.yang@xxxxxxxxx>
The per-port table uses extra1 for both the spintime minimum and the
port context of the active and hardware entries. During registration,
the loop also assigns the port pointer to vars[0].extra1, overwriting
the minimum. A spintime write can consequently be checked against data
from struct parport instead of the intended minimum.
Move the port context to priv and use numeric bounds for spintime.
Keep probe_info in data and set priv only for the entries that need the
port. Separating context from bounds prevents this overwrite.
The spintime bug exists in the base tree and can also be fixed separately;
this RFC does not depend on that fix.
Signed-off-by: Wen Yang <wen.yang@xxxxxxxxx>
---
drivers/parport/procfs.c | 51 +++++++++++++++-------------------------
1 file changed, 19 insertions(+), 32 deletions(-)
diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
index 1bfafc2a5724..6f6d96c37a93 100644
--- a/drivers/parport/procfs.c
+++ b/drivers/parport/procfs.c
@@ -36,7 +36,7 @@
static int do_active_device(const struct ctl_table *table, int write,
void *result, size_t *lenp, loff_t *ppos)
{
- struct parport *port = (struct parport *)table->extra1;
+ struct parport *port = table->priv;
char buffer[256];
struct pardevice *dev;
int len = 0;
@@ -73,7 +73,7 @@ static int do_active_device(const struct ctl_table *table, int write,
static int do_autoprobe(const struct ctl_table *table, int write,
void *result, size_t *lenp, loff_t *ppos)
{
- struct parport_device_info *info = table->extra2;
+ struct parport_device_info *info = table->data;
const char *str;
char buffer[256];
int len = 0;
@@ -116,7 +116,7 @@ static int do_autoprobe(const struct ctl_table *table, int write,
static int do_hardware_base_addr(const struct ctl_table *table, int write,
void *result, size_t *lenp, loff_t *ppos)
{
- struct parport *port = (struct parport *)table->extra1;
+ struct parport *port = table->priv;
char buffer[64];
int len = 0;
@@ -143,7 +143,7 @@ static int do_hardware_base_addr(const struct ctl_table *table, int write,
static int do_hardware_irq(const struct ctl_table *table, int write,
void *result, size_t *lenp, loff_t *ppos)
{
- struct parport *port = (struct parport *)table->extra1;
+ struct parport *port = table->priv;
char buffer[20];
int len = 0;
@@ -170,7 +170,7 @@ static int do_hardware_irq(const struct ctl_table *table, int write,
static int do_hardware_dma(const struct ctl_table *table, int write,
void *result, size_t *lenp, loff_t *ppos)
{
- struct parport *port = (struct parport *)table->extra1;
+ struct parport *port = table->priv;
char buffer[20];
int len = 0;
@@ -197,7 +197,7 @@ static int do_hardware_dma(const struct ctl_table *table, int write,
static int do_hardware_modes(const struct ctl_table *table, int write,
void *result, size_t *lenp, loff_t *ppos)
{
- struct parport *port = (struct parport *)table->extra1;
+ struct parport *port = table->priv;
char buffer[40];
int len = 0;
@@ -236,19 +236,6 @@ do { \
return 0;
}
-static const unsigned long parport_min_timeslice_value =
-PARPORT_MIN_TIMESLICE_VALUE;
-
-static const unsigned long parport_max_timeslice_value =
-PARPORT_MAX_TIMESLICE_VALUE;
-
-static const int parport_min_spintime_value =
-PARPORT_MIN_SPINTIME_VALUE;
-
-static const int parport_max_spintime_value =
-PARPORT_MAX_SPINTIME_VALUE;
-
-
struct parport_sysctl_table {
struct ctl_table_header *port_header;
struct ctl_table_header *devices_header;
@@ -270,8 +257,8 @@ static const struct parport_sysctl_table parport_sysctl_template = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = (void*) &parport_min_spintime_value,
- .extra2 = (void*) &parport_max_spintime_value
+ .min = PARPORT_MIN_SPINTIME_VALUE,
+ .max = PARPORT_MAX_SPINTIME_VALUE,
},
{
.procname = "base-addr",
@@ -367,8 +354,8 @@ parport_device_sysctl_template = {
.maxlen = sizeof(unsigned long),
.mode = 0644,
.proc_handler = proc_doulongvec_ms_jiffies_minmax,
- .extra1 = (void*) &parport_min_timeslice_value,
- .extra2 = (void*) &parport_max_timeslice_value
+ .min = PARPORT_MIN_TIMESLICE_VALUE,
+ .max = PARPORT_MAX_TIMESLICE_VALUE,
},
},
{
@@ -397,8 +384,8 @@ parport_default_sysctl_table = {
.maxlen = sizeof(parport_default_timeslice),
.mode = 0644,
.proc_handler = proc_doulongvec_ms_jiffies_minmax,
- .extra1 = (void*) &parport_min_timeslice_value,
- .extra2 = (void*) &parport_max_timeslice_value
+ .min = PARPORT_MIN_TIMESLICE_VALUE,
+ .max = PARPORT_MAX_TIMESLICE_VALUE,
},
{
.procname = "spintime",
@@ -406,8 +393,8 @@ parport_default_sysctl_table = {
.maxlen = sizeof(parport_default_spintime),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = (void*) &parport_min_spintime_value,
- .extra2 = (void*) &parport_max_spintime_value
+ .min = PARPORT_MIN_SPINTIME_VALUE,
+ .max = PARPORT_MAX_SPINTIME_VALUE,
},
}
};
@@ -422,15 +409,15 @@ int parport_proc_register(struct parport *port)
if (t == NULL)
return -ENOMEM;
- t->device_dir[0].extra1 = port;
+ t->device_dir[0].priv = port;
t->vars[0].data = &port->spintime;
- for (i = 0; i < 5; i++) {
- t->vars[i].extra1 = port;
+ for (i = 1; i < 5; i++)
+ t->vars[i].priv = port;
#ifdef CONFIG_PARPORT_1284
- t->vars[5 + i].extra2 = &port->probe_info[i];
+ for (i = 0; i < 5; i++)
+ t->vars[5 + i].data = &port->probe_info[i];
#endif /* IEEE 1284 support */
- }
tmp_dir_path = kasprintf(GFP_KERNEL, "dev/parport/%s/devices", port->name);
if (!tmp_dir_path) {
--
2.25.1