Skip to content

Commit

Permalink
Split asustor.c into asustor_main.c and asustor_gpl2.c
Browse files Browse the repository at this point in the history
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
  • Loading branch information
DanielGibson committed Nov 24, 2024
1 parent 9c3dee5 commit 2f7c0f6
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 43 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ KERNEL_MODULES := /lib/modules/$(TARGET)
KERNEL_BUILD := $(KERNEL_MODULES)/build
SYSTEM_MAP := /boot/System.map-$(TARGET)
DRIVER := asustor asustor_it87 asustor_gpio_it87
DRIVER_VERSION := v0.1
DRIVER_VERSION := v0.2
#DRIVER_VERSION ?= $(shell git describe --long)

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

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

all: modules

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

@mkdir -p $(DKMS_ROOT_PATH_ASUSTOR_IT87)
Expand Down
48 changes: 48 additions & 0 deletions asustor_gpl2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* asustor_gpl2.c - Code used by asustor.c that was copied from the Linux kernel
* and thus is licensed under GPLv2 ONLY, instead of GPLv2 or later.
*/

#include <linux/dmi.h>

bool asustor_dmi_matches(const struct dmi_system_id *dmi);

/**
* dmi_matches - check if dmi_system_id structure matches system DMI data
* @dmi: pointer to the dmi_system_id structure to check
*/
// copied from dmi_matches() in Linux 6.11.2 drivers/firmware/dmi_scan.c where it's private (static)
// with only one small change (dmi_val = dmi_get_system_info(s) instead of dmi_ident[s])
bool asustor_dmi_matches(const struct dmi_system_id *dmi)
{
int i;
const char *dmi_val;

for (i = 0; i < ARRAY_SIZE(dmi->matches); i++) {
int s = dmi->matches[i].slot;
if (s == DMI_NONE)
break;
if (s == DMI_OEM_STRING) {
/* DMI_OEM_STRING must be exact match */
const struct dmi_device *valid;

valid = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
dmi->matches[i].substr, NULL);
if (valid)
continue;
} else if ((dmi_val = dmi_get_system_info(s)) != NULL) {
if (dmi->matches[i].exact_match) {
if (!strcmp(dmi_val, dmi->matches[i].substr))
continue;
} else {
if (strstr(dmi_val, dmi->matches[i].substr))
continue;
}
}

/* No match */
return false;
}
return true;
}
48 changes: 7 additions & 41 deletions asustor.c → asustor_main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* asustor.c - Platform driver for ASUSTOR NAS hardware
* asustor_main.c - main part of asustor.ko, a platform driver for ASUSTOR NAS hardware
* (the other part is in asustor_gpl2.c which is GPL-2.0-only)
*
* Copyright (C) 2021 Mathias Fredriksson <[email protected]>
*/
Expand Down Expand Up @@ -408,45 +409,6 @@ static struct gpio_chip *find_chip_by_name(const char *name)
}
#endif

/**
* dmi_matches - check if dmi_system_id structure matches system DMI data
* @dmi: pointer to the dmi_system_id structure to check
*/
// copied from dmi_matches() in Linux 6.11.2 drivers/firmware/dmi_scan.c where it's private (static)
// with only one small change (dmi_val = dmi_get_system_info(s) instead of dmi_ident[s])
static bool dmi_matches(const struct dmi_system_id *dmi)
{
int i;
const char *dmi_val;

for (i = 0; i < ARRAY_SIZE(dmi->matches); i++) {
int s = dmi->matches[i].slot;
if (s == DMI_NONE)
break;
if (s == DMI_OEM_STRING) {
/* DMI_OEM_STRING must be exact match */
const struct dmi_device *valid;

valid = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
dmi->matches[i].substr, NULL);
if (valid)
continue;
} else if ((dmi_val = dmi_get_system_info(s)) != NULL) {
if (dmi->matches[i].exact_match) {
if (!strcmp(dmi_val, dmi->matches[i].substr))
continue;
} else {
if (strstr(dmi_val, dmi->matches[i].substr))
continue;
}
}

/* No match */
return false;
}
return true;
}

// How many PCI(e) devices with given vendor/device IDs exist in this system?
static int count_pci_device_instances(unsigned int vendor, unsigned int device)
{
Expand Down Expand Up @@ -492,6 +454,10 @@ static bool pci_devices_match(const struct asustor_driver_data *sys)
return true;
}

// returns true if dmi->matches match on the current system
// implemented in asustor_gpl2.c
extern bool asustor_dmi_matches(const struct dmi_system_id *dmi);

// find out which ASUSTOR system this is, based on asustor_systems[], including
// their linked asustor_driver_data's pci_matches
// returns NULL if this isn't a known system
Expand All @@ -509,7 +475,7 @@ static const struct dmi_system_id *find_matching_asustor_system(void)
break;
}

if (!dmi_matches(sys)) {
if (!asustor_dmi_matches(sys)) {
continue;
}

Expand Down

0 comments on commit 2f7c0f6

Please sign in to comment.