Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hv: 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.

Reviewed-by: Michael Kelley <mikelley@microsoft.com>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20220419113435.246203-5-krzysztof.kozlowski@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Krzysztof Kozlowski and committed by
Greg Kroah-Hartman
01ed1002 5688f212

+9 -25
+4 -24
drivers/hv/vmbus_drv.c
··· 575 575 const char *buf, size_t count) 576 576 { 577 577 struct hv_device *hv_dev = device_to_hv_device(dev); 578 - char *driver_override, *old, *cp; 578 + int ret; 579 579 580 - /* We need to keep extra room for a newline */ 581 - if (count >= (PAGE_SIZE - 1)) 582 - return -EINVAL; 583 - 584 - driver_override = kstrndup(buf, count, GFP_KERNEL); 585 - if (!driver_override) 586 - return -ENOMEM; 587 - 588 - cp = strchr(driver_override, '\n'); 589 - if (cp) 590 - *cp = '\0'; 591 - 592 - device_lock(dev); 593 - old = hv_dev->driver_override; 594 - if (strlen(driver_override)) { 595 - hv_dev->driver_override = driver_override; 596 - } else { 597 - kfree(driver_override); 598 - hv_dev->driver_override = NULL; 599 - } 600 - device_unlock(dev); 601 - 602 - kfree(old); 580 + ret = driver_set_override(dev, &hv_dev->driver_override, buf, count); 581 + if (ret) 582 + return ret; 603 583 604 584 return count; 605 585 }
+5 -1
include/linux/hyperv.h
··· 1257 1257 u16 device_id; 1258 1258 1259 1259 struct device device; 1260 - char *driver_override; /* Driver name to force a match */ 1260 + /* 1261 + * Driver name to force a match. Do not set directly, because core 1262 + * frees it. Use driver_set_override() to set or clear it. 1263 + */ 1264 + const char *driver_override; 1261 1265 1262 1266 struct vmbus_channel *channel; 1263 1267 struct kset *channels_kset;