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

[PATCH] ieee1394: fix calculation of csr->expire

This variant of calculate_expire() is more correct and easier to read.

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Signed-off-by: Ben Collins <bcollins@ubuntu.com>

authored by

Stefan Richter and committed by
Ben Collins
f0cbefe6 31a379e1

+10 -21
+10 -21
drivers/ieee1394/csr.c
··· 17 17 * 18 18 */ 19 19 20 - #include <linux/string.h> 20 + #include <linux/jiffies.h> 21 + #include <linux/kernel.h> 21 22 #include <linux/module.h> 22 23 #include <linux/moduleparam.h> 23 24 #include <linux/param.h> 24 25 #include <linux/spinlock.h> 26 + #include <linux/string.h> 25 27 26 28 #include "csr1212.h" 27 29 #include "ieee1394_types.h" ··· 151 149 152 150 /* 153 151 * HI == seconds (bits 0:2) 154 - * LO == fraction units of 1/8000 of a second, as per 1394 (bits 19:31) 152 + * LO == fractions of a second in units of 125usec (bits 19:31) 155 153 * 156 - * Convert to units and then to HZ, for comparison to jiffies. 157 - * 158 - * By default this will end up being 800 units, or 100ms (125usec per 159 - * unit). 160 - * 161 - * NOTE: The spec says 1/8000, but also says we can compute based on 1/8192 162 - * like CSR specifies. Should make our math less complex. 154 + * Convert SPLIT_TIMEOUT to jiffies. 155 + * The default and minimum as per 1394a-2000 clause 8.3.2.2.6 is 100ms. 163 156 */ 164 157 static inline void calculate_expire(struct csr_control *csr) 165 158 { 166 - unsigned long units; 159 + unsigned long usecs = 160 + (csr->split_timeout_hi & 0x07) * USEC_PER_SEC + 161 + (csr->split_timeout_lo >> 19) * 125L; 167 162 168 - /* Take the seconds, and convert to units */ 169 - units = (unsigned long)(csr->split_timeout_hi & 0x07) << 13; 170 - 171 - /* Add in the fractional units */ 172 - units += (unsigned long)(csr->split_timeout_lo >> 19); 173 - 174 - /* Convert to jiffies */ 175 - csr->expire = (unsigned long)(units * HZ) >> 13UL; 176 - 177 - /* Just to keep from rounding low */ 178 - csr->expire++; 163 + csr->expire = usecs_to_jiffies(usecs > 100000L ? usecs : 100000L); 179 164 180 165 HPSB_VERBOSE("CSR: setting expire to %lu, HZ=%u", csr->expire, HZ); 181 166 }