Skip to content

Commit 1e8ee51

Browse files
krzkgregkh
authored andcommitted
s390/cio: Use driver_set_override() instead of open-coding
Use a helper to set driver_override to the reduce amount of duplicated code. Make the driver_override field const char, because it is not modified by the core and it matches other subsystems. Acked-by: Vineeth Vijayan <vneethv@linux.ibm.com> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Link: https://lore.kernel.org/r/20220419113435.246203-7-krzysztof.kozlowski@linaro.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 23d99ba commit 1e8ee51

File tree

2 files changed

+9
-25
lines changed

2 files changed

+9
-25
lines changed

drivers/s390/cio/cio.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ struct subchannel {
103103
struct work_struct todo_work;
104104
struct schib_config config;
105105
u64 dma_mask;
106-
char *driver_override; /* Driver name to force a match */
106+
/*
107+
* Driver name to force a match. Do not set directly, because core
108+
* frees it. Use driver_set_override() to set or clear it.
109+
*/
110+
const char *driver_override;
107111
} __attribute__ ((aligned(8)));
108112

109113
DECLARE_PER_CPU_ALIGNED(struct irb, cio_irb);

drivers/s390/cio/css.c

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -338,31 +338,11 @@ static ssize_t driver_override_store(struct device *dev,
338338
const char *buf, size_t count)
339339
{
340340
struct subchannel *sch = to_subchannel(dev);
341-
char *driver_override, *old, *cp;
342-
343-
/* We need to keep extra room for a newline */
344-
if (count >= (PAGE_SIZE - 1))
345-
return -EINVAL;
346-
347-
driver_override = kstrndup(buf, count, GFP_KERNEL);
348-
if (!driver_override)
349-
return -ENOMEM;
350-
351-
cp = strchr(driver_override, '\n');
352-
if (cp)
353-
*cp = '\0';
354-
355-
device_lock(dev);
356-
old = sch->driver_override;
357-
if (strlen(driver_override)) {
358-
sch->driver_override = driver_override;
359-
} else {
360-
kfree(driver_override);
361-
sch->driver_override = NULL;
362-
}
363-
device_unlock(dev);
341+
int ret;
364342

365-
kfree(old);
343+
ret = driver_set_override(dev, &sch->driver_override, buf, count);
344+
if (ret)
345+
return ret;
366346

367347
return count;
368348
}

0 commit comments

Comments
 (0)