Skip to content

Commit 9c3dee5

Browse files
committed
Most changes suggested in the code review
including one to avoid leaking pci_dev structs in count_pci_device_instances()
1 parent 9e162ba commit 9c3dee5

File tree

2 files changed

+38
-23
lines changed

2 files changed

+38
-23
lines changed

README.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ The following DMI system-manufacturer / system-product-name combinations are cur
5959

6060
- LEDs (front panel, disk)
6161
- Represented as subdirectories in `/sys/class/leds/`
62-
- In the subdirectories, you can set `brightness` to 0 or 1 to switch the LED off or on, for example
63-
`$ echo 1 | sudo tee blue:power/brightness`
64-
similarly, the `trigger` can be configured, see [below](#set-triggers-for-leds)
62+
- In the subdirectories, you can set `brightness` to 0 or 1 to switch the LED off or on
63+
(for example `echo 1 | sudo tee blue:power/brightness`). Similarly, the `trigger` can
64+
also be configured, see [below](#set-triggers-for-leds).
6565
- Sometimes the name of an LED doesn't exactly represent its color, for example, on the
6666
*Flashstor FS6712X*, the `blue:lan` LED is actually purple when connected with 10GBit
6767
(but blue when connected with 1GBit). Also, sometimes two LEDs physically appear as one, so
@@ -154,6 +154,8 @@ echo r8169-0-200:00:link > /sys/class/leds/blue\:lan
154154
one being marked with square brackes (e.g. `[none] kbd-scrolllock kbd-numlock kbd-capslock ...`).
155155

156156
Note that currently the disk-related triggers (like `disk-activity`) do **not** work with NVME drives.
157+
That's a general limitation of the Linux kernel that is independent of this project.
158+
If this feature is ever implemented in the kernel, it will automatically work with this driver.
157159

158160
### `it87` and PWM polarity
159161

@@ -168,19 +170,21 @@ Note that `it87` conflicts with `asustor-it87`, you may wish to add `it87` to th
168170
If the `asustor` kernel module doesn't detect your device correctly, you can force it to treat your
169171
ASUSTOR device as one of the supported devices by setting the `force_device` module parameter.
170172

171-
can be used like:
172-
`$ sudo modprobe asustor force_device=AS66xx`
173-
or by creating an `/etc/modprobe.d/asustor.conf` text file with the following content:
173+
This can be done manually with `sudo modprobe asustor force_device=AS66xx`, or by creating
174+
`/etc/modprobe.d/asustor.conf` with the following content:
174175

175176
```
176177
# override device detection of the asustor kernel module
177178
options asustor force_device=FS67xx
178179
```
179180

180-
Of course you should replace "FS67xx" with the device you want to try, see the [Compatiblity](#compatibility)
181-
section above for how the `asustor` kernel module identifies devices, or
182-
`$ sudo modinfo -p asustor`
183-
which will print a short usage info including the currently supported device names for `force_device`.
181+
Please replace "FS67xx" with the device you want to try.
182+
See the [Compatiblity](#compatibility)-section above for how the `asustor` kernel module identifies devices.
183+
Alternatively, can use the following command to print module parameters, including the currently supported device names for `force_device`:
184+
185+
```console
186+
$ sudo modinfo -p asustor
187+
```
184188

185189
_**NOTE:** If you need to use the `force_device` parameter to make your device work, please open an issue
186190
so the detection logic in the `asustor` kernel module can be fixed to properly support it._

asustor.c

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ struct pci_device_match {
248248
int16_t max_count; // how often that device should exist at most
249249
};
250250

251+
enum {
252+
DEVICE_COUNT_MAX = 0x7fff // INT16_MAX - used for "no upper limit"
253+
};
254+
251255
// ASUSTOR Platform.
252256
struct asustor_driver_data {
253257
const char *name; // used for force_device and for some log messages
@@ -268,8 +272,8 @@ static struct asustor_driver_data asustor_fs6700_driver_data = {
268272
.pci_matches = {
269273
// PCI bridge: ASMedia Technology Inc. ASM2806 4-Port PCIe x2 Gen3 Packet Switch (rev 01)
270274
// FS6712X seems to have 15 of these, no idea about FS6706T (so I keep min_count at 1)
271-
// currently the upper limit doesn't matter so I just use 10000
272-
{ 0x1b21, 0x2806, 1, 10000 },
275+
// currently the upper limit doesn't matter so I just use DEVICE_COUNT_MAX
276+
{ 0x1b21, 0x2806, 1, DEVICE_COUNT_MAX },
273277
},
274278
.leds = &asustor_fs6700_gpio_leds_lookup,
275279
.keys = &asustor_fs6700_gpio_keys_lookup,
@@ -280,7 +284,8 @@ static struct asustor_driver_data asustor_6700_driver_data = {
280284
// AS67xx needs to match PCI devices because it has the same DMI data as *F*S67xx
281285
.pci_matches = {
282286
// PCI bridge: ASMedia Technology Inc. ASM2806 4-Port PCIe x2 Gen3 Packet Switch (rev 01)
283-
// *F*S67xx seems to use these, I think *A*S67xx doesn't, so expect 0
287+
// *F*S67xx seems to use these, *A*S67xx doesn't, so expect 0
288+
// (BTW, AS6706T has 5x "ASM2812 6-Port PCIe x4 Gen3 Packet Switch" [1b21:2812], I hope *F*S6706T doesn't)
284289
{ 0x1b21, 0x2806, 0, 0 },
285290
},
286291
.leds = &asustor_6700_gpio_leds_lookup,
@@ -319,7 +324,7 @@ static const struct dmi_system_id asustor_systems[] = {
319324
// NOTE: each entry in this table must have its own unique asustor_driver_data
320325
// (having a unique .name) set as .driver_data
321326
{
322-
// Note: yes, this is the same DMI match as the next entry, because just by DMI,
327+
// NOTE: yes, this is the same DMI match as the next entry, because just by DMI,
323328
// FS67xx and AS67xx can't be told apart. But our custom matching logic
324329
// in find_matching_asustor_system() also takes driver_data->pci_matches[]
325330
// into account, so that should be ok.
@@ -330,7 +335,7 @@ static const struct dmi_system_id asustor_systems[] = {
330335
.driver_data = &asustor_fs6700_driver_data,
331336
},
332337
{
333-
// Note: This not only matches (and works with) AS670xT (Lockerstor Gen2),
338+
// NOTE: This not only matches (and works with) AS670xT (Lockerstor Gen2),
334339
// but also AS540xT (Nimbustor Gen2)
335340
.matches = {
336341
DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
@@ -442,22 +447,28 @@ static bool dmi_matches(const struct dmi_system_id *dmi)
442447
return true;
443448
}
444449

445-
// how often does the PCI(e) device with given vendor/device IDs exist in this system?
450+
// How many PCI(e) devices with given vendor/device IDs exist in this system?
446451
static int count_pci_device_instances(unsigned int vendor, unsigned int device)
447452
{
448-
// start with -1 as the do-while loop runs at least once even if nothing is found
449-
int ret = -1;
450-
struct pci_dev *pd = NULL;
451-
do {
453+
int ret = 0;
454+
struct pci_dev *pd, *last_pd = NULL;
455+
456+
while ((pd = pci_get_device(vendor, device, last_pd)) != NULL) {
457+
if (last_pd) {
458+
pci_dev_put(last_pd);
459+
}
460+
last_pd = pd;
452461
++ret;
453-
pd = pci_get_device(vendor, device, pd);
454-
} while (pd != NULL);
462+
}
463+
if (last_pd) {
464+
pci_dev_put(last_pd);
465+
}
455466
return ret;
456467
}
457468

458469
// check if sys->pci_matches[] match with the PCI devices in the system
459470
// NOTE: this only checks if the devices in sys->pci_matches[] exist in the system
460-
// with the expected count (or do *not* exist if the counts are 0),
471+
// with the expected count (or the device does *not* exist if the counts are 0),
461472
// PCI devices existing that aren't listed in sys->pci_matches[] is expected
462473
// and does not make this function fail.
463474
static bool pci_devices_match(const struct asustor_driver_data *sys)

0 commit comments

Comments
 (0)