Skip to content

SoftPWM fails to build on kernel >= 4.10 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
AHeinlein opened this issue Sep 9, 2019 · 6 comments
Open

SoftPWM fails to build on kernel >= 4.10 #3

AHeinlein opened this issue Sep 9, 2019 · 6 comments
Labels
bug Something isn't working

Comments

@AHeinlein
Copy link

I don't know if this project is still alive...

The softpwm module doesn't build on kernels from 4.10 onward. It fails with

Mo 9. Sep 14:31:17 CEST 2019
make: Verzeichnis „/var/lib/dkms/softpwm/20180507/build“ wird betreten
make -C /lib/modules/4.19.0-5-amd64/build M=/var/lib/dkms/softpwm/20180507/build modules
make[1]: Verzeichnis „/var/lib/dkms/softpwm/20180507/build“ wird betreten
make[1]: Warnung: Kein Jobserver verfügbar: -j1 wird gesetzt. Fügen Sie der Ursprungsregel
„+“ hinzu.
  CC [M]  /var/lib/dkms/softpwm/20180507/build/softpwm.o
/var/lib/dkms/softpwm/20180507/build/softpwm.c:214:3: error: ‘struct class’ has no member named ‘class_attrs’; did you mean ‘class_groups’?
  .class_attrs = soft_pwm_class_attrs,
   ^~~~~~~~~~~
   class_groups
/var/lib/dkms/softpwm/20180507/build/softpwm.c:214:17: error: initialization of ‘const struct attribute_group **’ from incompatible pointer type ‘struct class_attribute *’ [-Werror=incompatible-pointer-types]
  .class_attrs = soft_pwm_class_attrs,
                 ^~~~~~~~~~~~~~~~~~~~
/var/lib/dkms/softpwm/20180507/build/softpwm.c:214:17: note: (near initialization for ‘soft_pwm_class.class_groups’)
/var/lib/dkms/softpwm/20180507/build/softpwm.c: In function ‘soft_pwm_hrtimer_callback’:
/var/lib/dkms/softpwm/20180507/build/softpwm.c:311:23: error: request for member ‘tv64’ in something not a structure or union
    if (desc->next_tick.tv64 <= now.tv64) {
                       ^
/var/lib/dkms/softpwm/20180507/build/softpwm.c:311:35: error: request for member ‘tv64’ in something not a structure or union
    if (desc->next_tick.tv64 <= now.tv64) {
                                   ^
/var/lib/dkms/softpwm/20180507/build/softpwm.c:321:21: error: request for member ‘tv64’ in something not a structure or union
      desc->next_tick.tv64 = KTIME_MAX;
                     ^
/var/lib/dkms/softpwm/20180507/build/softpwm.c:330:17: error: request for member ‘tv64’ in something not a structure or union
    if (next_tick.tv64 == 0 ||
                 ^
/var/lib/dkms/softpwm/20180507/build/softpwm.c:331:20: error: request for member ‘tv64’ in something not a structure or union
     desc->next_tick.tv64 < next_tick.tv64) {
                    ^
/var/lib/dkms/softpwm/20180507/build/softpwm.c:331:37: error: request for member ‘tv64’ in something not a structure or union
     desc->next_tick.tv64 < next_tick.tv64) {
                                     ^
/var/lib/dkms/softpwm/20180507/build/softpwm.c:332:14: error: request for member ‘tv64’ in something not a structure or union
     next_tick.tv64 = desc->next_tick.tv64;
              ^
/var/lib/dkms/softpwm/20180507/build/softpwm.c:332:37: error: request for member ‘tv64’ in something not a structure or union
     next_tick.tv64 = desc->next_tick.tv64;
                                     ^
/var/lib/dkms/softpwm/20180507/build/softpwm.c:343:15: error: request for member ‘tv64’ in something not a structure or union
  if (next_tick.tv64 > 0)
               ^
cc1: some warnings being treated as errors
make[4]: *** [/usr/src/linux-headers-4.19.0-5-common/scripts/Makefile.build:315: /var/lib/dkms/softpwm/20180507/build/softpwm.o] Fehler 1
make[3]: *** [/usr/src/linux-headers-4.19.0-5-common/Makefile:1539: _module_/var/lib/dkms/softpwm/20180507/build] Fehler 2
make[2]: *** [Makefile:146: sub-make] Fehler 2
make[1]: *** [Makefile:8: all] Fehler 2
make[1]: Verzeichnis „/usr/src/linux-headers-4.19.0-5-amd64“ wird verlassen
make: *** [Makefile:3: all] Fehler 2
make: Verzeichnis „/var/lib/dkms/softpwm/20180507/build“ wird verlassen

Quick googling tells me that this is a common error introduced with kernel 4.10, but I am not a programmer and cannot easily fix this.

@stupidpupil stupidpupil added the bug Something isn't working label Sep 9, 2019
@stupidpupil
Copy link
Owner

It's not exactly dead. I'm glad you raised this issue!

I'm barely a programmer, I'm afraid, but I'll see if I can work out how hard this will be to fix (or better yet if someone else has already fixed the driver).

@stupidpupil
Copy link
Owner

An alternative is to drop the SoftPWM driver and do the PWM is userspace, I guess.

@TonyPuryer
Copy link

Bumping this issue just to see if a fix or workaround has been found. I encountered the exact same error log when attempting to install the led drivers package on openmediavault 5.5.3-1. Thanks in advance.

@abonforti
Copy link

Hi, any update here guys?

@YNikiforov
Copy link

Here is a fix. As far as I understood while lurking into kernel code for a few nights

  • .class_attrs structure must be wrapped into .class_groups
  • .tv64 does not exist anymore and it looks kinda not needed as ktime_t is signed 64-bit in nanoseconds and is already comparable.

But I'm not a kernel developer, actually haven't done any code for Linux ever, so I'd appreciate a code review.

These changes were tested on openmediavault 5.6.5-1 (Usul) with Proxmox test kernel 5.11.7-1-pve. During compilation I had an error mentioning scripts/module.lds like here https://github.com/mkubecek/vmware-host-modules/issues/88 and the proposed solution worked for me.

Also the version without PWM proposed by @gpancot in #4 works fine for me. So if anyone doesn't like softpwm it makes perfect sense to use this on/off option.

So here is the diff, check it out, comment, try, have fun.

diff --git a/src/softpwm/dkms.conf b/src/softpwm/dkms.conf
index 0e9f44a..c274dd2 100644
--- a/src/softpwm/dkms.conf
+++ b/src/softpwm/dkms.conf
@@ -4,5 +4,5 @@ BUILT_MODULE_NAME=softpwm
 BUILT_MODULE_LOCATION=.
 DEST_MODULE_LOCATION=/updates
 PACKAGE_NAME=softpwm
-PACKAGE_VERSION=20180507
+PACKAGE_VERSION=20210503
 REMAKE_INITRD=yes
diff --git a/src/softpwm/softpwm.c b/src/softpwm/softpwm.c
index 7fe69b5..0453e4a 100644
--- a/src/softpwm/softpwm.c
+++ b/src/softpwm/softpwm.c
@@ -12,6 +12,7 @@ http://www.acmesystems.it/soft_pwm
 http://www.acmesystems.it/DAISY-2
 */
 
+/* Fix for newer kernels >= 4.10 by Yurii Nikiforov */
 
 #include <linux/kernel.h>
 #include <linux/module.h>
@@ -201,17 +202,21 @@ done:
 	return status ? : len;
 }
 
-/* Sysfs definitions for soft_pwm class */
-static struct class_attribute soft_pwm_class_attrs[] = {
-	__ATTR(export,   0200, NULL, export_store),
-	__ATTR(unexport, 0200, NULL, unexport_store),
-	__ATTR_NULL,
+static CLASS_ATTR_WO(export);
+static CLASS_ATTR_WO(unexport);
+
+static struct attribute *soft_pwm_class_attrs[] = {
+	&class_attr_export.attr,
+	&class_attr_unexport.attr,
+	NULL,
 };
 
+ATTRIBUTE_GROUPS(soft_pwm_class);
+
 static struct class soft_pwm_class = {
 	.name = "soft_pwm",
 	.owner = THIS_MODULE,
-	.class_attrs = soft_pwm_class_attrs,
+	.class_groups = soft_pwm_class_groups,
 };
 
 /* Setup the sysfs directory for a claimed PWM device */
@@ -308,7 +313,7 @@ enum hrtimer_restart soft_pwm_hrtimer_callback(struct hrtimer *timer) {
 		else if (desc->pulse >= desc->period)
 			desc->value = 1;
 		else {
-			if (desc->next_tick.tv64 <= now.tv64) {
+			if (desc->next_tick <= now) {
 				desc->value = 1 - desc->value;
 
 				desc->counter ++;
@@ -318,7 +323,7 @@ enum hrtimer_restart soft_pwm_hrtimer_callback(struct hrtimer *timer) {
 				if (desc->pulse == 0 ||
 					desc->pulse == desc->period ||
 					desc->pulses == 0) {
-					desc->next_tick.tv64 = KTIME_MAX;
+					desc->next_tick = KTIME_MAX;
 				} else {
 					t = desc->value ?
 						desc->pulse :
@@ -327,9 +332,9 @@ enum hrtimer_restart soft_pwm_hrtimer_callback(struct hrtimer *timer) {
 						t * 1000);
 				}
 			}
-			if (next_tick.tv64 == 0 ||
-				desc->next_tick.tv64 < next_tick.tv64) {
-				next_tick.tv64 = desc->next_tick.tv64;
+			if (next_tick == 0 ||
+				desc->next_tick < next_tick) {
+				next_tick = desc->next_tick;
 			}
 		}
 
@@ -340,7 +345,7 @@ next:
 		}
 	}
 
-	if (next_tick.tv64 > 0)
+	if (next_tick > 0)
 		hrtimer_start(&hr_timer, next_tick, HRTIMER_MODE_ABS);
 
 	return HRTIMER_NORESTART;
@@ -351,7 +356,7 @@ static int __init soft_pwm_init(void){
 	//struct timespec tp;
 
 	int status;
-	printk(KERN_INFO "SoftPWM v0.2-acme initializing.\n");
+	printk(KERN_INFO "SoftPWM v0.3-acme initializing.\n");
 
 	//hrtimer_get_res(CLOCK_MONOTONIC, &tp);
 	//printk(KERN_INFO "Clock resolution is %ldns\n", tp.tv_nsec);
@@ -394,4 +399,3 @@ static void __exit soft_pwm_exit(void){
 
 module_init(soft_pwm_init);
 module_exit(soft_pwm_exit);
-

Download as patch.txt

@stupidpupil stupidpupil pinned this issue Dec 1, 2021
@Wohlstand
Copy link

@YNikiforov, just now I tested your patch, it builds, and works, however, for my device I had to change the gpio chip with the gpiochip768 from gpiochip256 because it appears at my device.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants