Skip to content

Commit e61ad9d

Browse files
committed
Split asustor.c into asustor_main.c and asustor_gpl2.c
asustor_main.c is licensed under GPLv2 or later, while asustor_gpl2.c is licensed under GPLv2 only. dmi_matches() is moved from asustor(_main).c to asustor_gpl2.c, because it's copied from drivers/firmware/dmi_scan.c which is released under GPLv2 only. asustor.c had to be renamed to asustor_main.c, because apparently the kernel build system only supports a source file with the same name as the module if that module is built only from that file. I also bumped the DRIVER_VERSION (used for DKMS) from v0.1 to v0.2 to hopefully avoid conflicts due to all these changes
1 parent 9c3dee5 commit e61ad9d

File tree

3 files changed

+60
-43
lines changed

3 files changed

+60
-43
lines changed

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ KERNEL_MODULES := /lib/modules/$(TARGET)
33
KERNEL_BUILD := $(KERNEL_MODULES)/build
44
SYSTEM_MAP := /boot/System.map-$(TARGET)
55
DRIVER := asustor asustor_it87 asustor_gpio_it87
6-
DRIVER_VERSION := v0.1
6+
DRIVER_VERSION := v0.2
77
#DRIVER_VERSION ?= $(shell git describe --long)
88

99
# DKMS
@@ -17,6 +17,8 @@ asustor_gpio_it87_DEST_DIR = $(KERNEL_MODULES)/kernel/drivers/gpio
1717

1818
obj-m := $(patsubst %,%.o,$(DRIVER))
1919
obj-ko := $(patsubst %,%.ko,$(DRIVER))
20+
# asustor.o is built from two source files for license reasons
21+
asustor-y := asustor_main.o asustor_gpl2.o
2022

2123
all: modules
2224

@@ -38,8 +40,9 @@ dkms:
3840
@mkdir -p $(DKMS_ROOT_PATH_ASUSTOR)
3941
@echo "obj-m := asustor.o" >>$(DKMS_ROOT_PATH_ASUSTOR)/Makefile
4042
@echo "obj-ko := asustor.ko" >>$(DKMS_ROOT_PATH_ASUSTOR)/Makefile
43+
@echo "asustor-y := asustor_main.o asustor_gpl2.o" >>$(DKMS_ROOT_PATH_ASUSTOR)/Makefile
4144
@cp dkms.conf $(DKMS_ROOT_PATH_ASUSTOR)
42-
@cp asustor.c $(DKMS_ROOT_PATH_ASUSTOR)
45+
@cp asustor_main.c asustor_gpl2.c $(DKMS_ROOT_PATH_ASUSTOR)
4346
@sed -i -e '/^PACKAGE_VERSION=/ s/=.*/=\"$(DRIVER_VERSION)\"/' $(DKMS_ROOT_PATH_ASUSTOR)/dkms.conf
4447

4548
@mkdir -p $(DKMS_ROOT_PATH_ASUSTOR_IT87)

asustor_gpl2.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* asustor_gpl2.c - Functions used by asustor_main.c (for asustor.ko) that were copied from the
4+
* Linux kernel and are licensed under GPLv2 ONLY, instead of GPLv2 or later.
5+
*/
6+
7+
#include <linux/dmi.h>
8+
9+
bool asustor_dmi_matches(const struct dmi_system_id *dmi);
10+
11+
/**
12+
* dmi_matches - check if dmi_system_id structure matches system DMI data
13+
* @dmi: pointer to the dmi_system_id structure to check
14+
*/
15+
// copied from dmi_matches() in Linux 6.11.2 drivers/firmware/dmi_scan.c where it's private (static)
16+
// with only one small change (dmi_val = dmi_get_system_info(s) instead of dmi_ident[s])
17+
bool asustor_dmi_matches(const struct dmi_system_id *dmi)
18+
{
19+
int i;
20+
const char *dmi_val;
21+
22+
for (i = 0; i < ARRAY_SIZE(dmi->matches); i++) {
23+
int s = dmi->matches[i].slot;
24+
if (s == DMI_NONE)
25+
break;
26+
if (s == DMI_OEM_STRING) {
27+
/* DMI_OEM_STRING must be exact match */
28+
const struct dmi_device *valid;
29+
30+
valid = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
31+
dmi->matches[i].substr, NULL);
32+
if (valid)
33+
continue;
34+
} else if ((dmi_val = dmi_get_system_info(s)) != NULL) {
35+
if (dmi->matches[i].exact_match) {
36+
if (!strcmp(dmi_val, dmi->matches[i].substr))
37+
continue;
38+
} else {
39+
if (strstr(dmi_val, dmi->matches[i].substr))
40+
continue;
41+
}
42+
}
43+
44+
/* No match */
45+
return false;
46+
}
47+
return true;
48+
}

asustor.c renamed to asustor_main.c

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0-or-later
22
/*
3-
* asustor.c - Platform driver for ASUSTOR NAS hardware
3+
* asustor_main.c - main part of asustor.ko, a platform driver for ASUSTOR NAS hardware
4+
* (the other part is in asustor_gpl2.c which is GPL-2.0-only)
45
*
56
* Copyright (C) 2021 Mathias Fredriksson <mafredri@gmail.com>
67
*/
@@ -408,45 +409,6 @@ static struct gpio_chip *find_chip_by_name(const char *name)
408409
}
409410
#endif
410411

411-
/**
412-
* dmi_matches - check if dmi_system_id structure matches system DMI data
413-
* @dmi: pointer to the dmi_system_id structure to check
414-
*/
415-
// copied from dmi_matches() in Linux 6.11.2 drivers/firmware/dmi_scan.c where it's private (static)
416-
// with only one small change (dmi_val = dmi_get_system_info(s) instead of dmi_ident[s])
417-
static bool dmi_matches(const struct dmi_system_id *dmi)
418-
{
419-
int i;
420-
const char *dmi_val;
421-
422-
for (i = 0; i < ARRAY_SIZE(dmi->matches); i++) {
423-
int s = dmi->matches[i].slot;
424-
if (s == DMI_NONE)
425-
break;
426-
if (s == DMI_OEM_STRING) {
427-
/* DMI_OEM_STRING must be exact match */
428-
const struct dmi_device *valid;
429-
430-
valid = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
431-
dmi->matches[i].substr, NULL);
432-
if (valid)
433-
continue;
434-
} else if ((dmi_val = dmi_get_system_info(s)) != NULL) {
435-
if (dmi->matches[i].exact_match) {
436-
if (!strcmp(dmi_val, dmi->matches[i].substr))
437-
continue;
438-
} else {
439-
if (strstr(dmi_val, dmi->matches[i].substr))
440-
continue;
441-
}
442-
}
443-
444-
/* No match */
445-
return false;
446-
}
447-
return true;
448-
}
449-
450412
// How many PCI(e) devices with given vendor/device IDs exist in this system?
451413
static int count_pci_device_instances(unsigned int vendor, unsigned int device)
452414
{
@@ -492,6 +454,10 @@ static bool pci_devices_match(const struct asustor_driver_data *sys)
492454
return true;
493455
}
494456

457+
// returns true if dmi->matches match on the current system
458+
// implemented in asustor_gpl2.c
459+
extern bool asustor_dmi_matches(const struct dmi_system_id *dmi);
460+
495461
// find out which ASUSTOR system this is, based on asustor_systems[], including
496462
// their linked asustor_driver_data's pci_matches
497463
// returns NULL if this isn't a known system
@@ -509,7 +475,7 @@ static const struct dmi_system_id *find_matching_asustor_system(void)
509475
break;
510476
}
511477

512-
if (!dmi_matches(sys)) {
478+
if (!asustor_dmi_matches(sys)) {
513479
continue;
514480
}
515481

0 commit comments

Comments
 (0)