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

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'counter-fixes-for-6.1a' of git://git.kernel.org/pub/scm/linux/kernel/git/wbg/counter into char-misc-linus

William writes:
"First set of Counter fixes for 6.1 cycle

Typical driver fixes for races and bugs. This also includes a sparse
warning fix for the recently introduced counter_array API: the macro
DEFINE_COUNTER_ARRAY_POLARITY() is reduced to a simple structure
definition rather than multiple data structure definitions.
- 104-quad-8
* Fix race getting function mode and direction
- microchip-tcb-capture
* Handle Signal1 read and Synapse
- ti-ecap-capture
* fix IS_ERR() vs NULL check
- counter
* Reduce DEFINE_COUNTER_ARRAY_POLARITY() to defining counter_array"

* tag 'counter-fixes-for-6.1a' of git://git.kernel.org/pub/scm/linux/kernel/git/wbg/counter:
counter: 104-quad-8: Fix race getting function mode and direction
counter: microchip-tcb-capture: Handle Signal1 read and Synapse
counter: ti-ecap-capture: fix IS_ERR() vs NULL check
counter: Reduce DEFINE_COUNTER_ARRAY_POLARITY() to defining counter_array

+62 -32
+42 -22
drivers/counter/104-quad-8.c
··· 232 COUNTER_FUNCTION_QUADRATURE_X4, 233 }; 234 235 static int quad8_function_read(struct counter_device *counter, 236 struct counter_count *count, 237 enum counter_function *function) 238 { 239 struct quad8 *const priv = counter_priv(counter); 240 - const int id = count->id; 241 unsigned long irqflags; 242 243 spin_lock_irqsave(&priv->lock, irqflags); 244 245 - if (priv->quadrature_mode[id]) 246 - switch (priv->quadrature_scale[id]) { 247 - case 0: 248 - *function = COUNTER_FUNCTION_QUADRATURE_X1_A; 249 - break; 250 - case 1: 251 - *function = COUNTER_FUNCTION_QUADRATURE_X2_A; 252 - break; 253 - case 2: 254 - *function = COUNTER_FUNCTION_QUADRATURE_X4; 255 - break; 256 - } 257 - else 258 - *function = COUNTER_FUNCTION_PULSE_DIRECTION; 259 260 spin_unlock_irqrestore(&priv->lock, irqflags); 261 262 - return 0; 263 } 264 265 static int quad8_function_write(struct counter_device *counter, ··· 370 enum counter_synapse_action *action) 371 { 372 struct quad8 *const priv = counter_priv(counter); 373 int err; 374 enum counter_function function; 375 const size_t signal_a_id = count->synapses[0].signal->id; ··· 386 return 0; 387 } 388 389 - err = quad8_function_read(counter, count, &function); 390 - if (err) 391 return err; 392 393 /* Default action mode */ 394 *action = COUNTER_SYNAPSE_ACTION_NONE; ··· 413 return 0; 414 case COUNTER_FUNCTION_QUADRATURE_X1_A: 415 if (synapse->signal->id == signal_a_id) { 416 - err = quad8_direction_read(counter, count, &direction); 417 - if (err) 418 - return err; 419 - 420 if (direction == COUNTER_COUNT_DIRECTION_FORWARD) 421 *action = COUNTER_SYNAPSE_ACTION_RISING_EDGE; 422 else
··· 232 COUNTER_FUNCTION_QUADRATURE_X4, 233 }; 234 235 + static int quad8_function_get(const struct quad8 *const priv, const size_t id, 236 + enum counter_function *const function) 237 + { 238 + if (!priv->quadrature_mode[id]) { 239 + *function = COUNTER_FUNCTION_PULSE_DIRECTION; 240 + return 0; 241 + } 242 + 243 + switch (priv->quadrature_scale[id]) { 244 + case 0: 245 + *function = COUNTER_FUNCTION_QUADRATURE_X1_A; 246 + return 0; 247 + case 1: 248 + *function = COUNTER_FUNCTION_QUADRATURE_X2_A; 249 + return 0; 250 + case 2: 251 + *function = COUNTER_FUNCTION_QUADRATURE_X4; 252 + return 0; 253 + default: 254 + /* should never reach this path */ 255 + return -EINVAL; 256 + } 257 + } 258 + 259 static int quad8_function_read(struct counter_device *counter, 260 struct counter_count *count, 261 enum counter_function *function) 262 { 263 struct quad8 *const priv = counter_priv(counter); 264 unsigned long irqflags; 265 + int retval; 266 267 spin_lock_irqsave(&priv->lock, irqflags); 268 269 + retval = quad8_function_get(priv, count->id, function); 270 271 spin_unlock_irqrestore(&priv->lock, irqflags); 272 273 + return retval; 274 } 275 276 static int quad8_function_write(struct counter_device *counter, ··· 359 enum counter_synapse_action *action) 360 { 361 struct quad8 *const priv = counter_priv(counter); 362 + unsigned long irqflags; 363 int err; 364 enum counter_function function; 365 const size_t signal_a_id = count->synapses[0].signal->id; ··· 374 return 0; 375 } 376 377 + spin_lock_irqsave(&priv->lock, irqflags); 378 + 379 + /* Get Count function and direction atomically */ 380 + err = quad8_function_get(priv, count->id, &function); 381 + if (err) { 382 + spin_unlock_irqrestore(&priv->lock, irqflags); 383 return err; 384 + } 385 + err = quad8_direction_read(counter, count, &direction); 386 + if (err) { 387 + spin_unlock_irqrestore(&priv->lock, irqflags); 388 + return err; 389 + } 390 + 391 + spin_unlock_irqrestore(&priv->lock, irqflags); 392 393 /* Default action mode */ 394 *action = COUNTER_SYNAPSE_ACTION_NONE; ··· 389 return 0; 390 case COUNTER_FUNCTION_QUADRATURE_X1_A: 391 if (synapse->signal->id == signal_a_id) { 392 if (direction == COUNTER_COUNT_DIRECTION_FORWARD) 393 *action = COUNTER_SYNAPSE_ACTION_RISING_EDGE; 394 else
+14 -4
drivers/counter/microchip-tcb-capture.c
··· 28 int qdec_mode; 29 int num_channels; 30 int channel[2]; 31 - bool trig_inverted; 32 }; 33 34 static const enum counter_function mchp_tc_count_functions[] = { ··· 152 153 regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], SR), &sr); 154 155 - if (priv->trig_inverted) 156 sigstatus = (sr & ATMEL_TC_MTIOB); 157 else 158 sigstatus = (sr & ATMEL_TC_MTIOA); ··· 169 { 170 struct mchp_tc_data *const priv = counter_priv(counter); 171 u32 cmr; 172 173 regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CMR), &cmr); 174 ··· 209 struct mchp_tc_data *const priv = counter_priv(counter); 210 u32 edge = ATMEL_TC_ETRGEDG_NONE; 211 212 - /* QDEC mode is rising edge only */ 213 - if (priv->qdec_mode) 214 return -EINVAL; 215 216 switch (action) {
··· 28 int qdec_mode; 29 int num_channels; 30 int channel[2]; 31 }; 32 33 static const enum counter_function mchp_tc_count_functions[] = { ··· 153 154 regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], SR), &sr); 155 156 + if (signal->id == 1) 157 sigstatus = (sr & ATMEL_TC_MTIOB); 158 else 159 sigstatus = (sr & ATMEL_TC_MTIOA); ··· 170 { 171 struct mchp_tc_data *const priv = counter_priv(counter); 172 u32 cmr; 173 + 174 + if (priv->qdec_mode) { 175 + *action = COUNTER_SYNAPSE_ACTION_BOTH_EDGES; 176 + return 0; 177 + } 178 + 179 + /* Only TIOA signal is evaluated in non-QDEC mode */ 180 + if (synapse->signal->id != 0) { 181 + *action = COUNTER_SYNAPSE_ACTION_NONE; 182 + return 0; 183 + } 184 185 regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CMR), &cmr); 186 ··· 199 struct mchp_tc_data *const priv = counter_priv(counter); 200 u32 edge = ATMEL_TC_ETRGEDG_NONE; 201 202 + /* QDEC mode is rising edge only; only TIOA handled in non-QDEC mode */ 203 + if (priv->qdec_mode || synapse->signal->id != 0) 204 return -EINVAL; 205 206 switch (action) {
+4 -3
drivers/counter/ti-ecap-capture.c
··· 377 COUNTER_SIGNAL_POLARITY_NEGATIVE, 378 }; 379 380 - static DEFINE_COUNTER_ARRAY_POLARITY(ecap_cnt_pol_array, ecap_cnt_pol_avail, ECAP_NB_CEVT); 381 382 static struct counter_comp ecap_cnt_signal_ext[] = { 383 COUNTER_COMP_ARRAY_POLARITY(ecap_cnt_pol_read, ecap_cnt_pol_write, ecap_cnt_pol_array), ··· 480 int ret; 481 482 counter_dev = devm_counter_alloc(dev, sizeof(*ecap_dev)); 483 - if (IS_ERR(counter_dev)) 484 - return PTR_ERR(counter_dev); 485 486 counter_dev->name = ECAP_DRV_NAME; 487 counter_dev->parent = dev;
··· 377 COUNTER_SIGNAL_POLARITY_NEGATIVE, 378 }; 379 380 + static DEFINE_COUNTER_AVAILABLE(ecap_cnt_pol_available, ecap_cnt_pol_avail); 381 + static DEFINE_COUNTER_ARRAY_POLARITY(ecap_cnt_pol_array, ecap_cnt_pol_available, ECAP_NB_CEVT); 382 383 static struct counter_comp ecap_cnt_signal_ext[] = { 384 COUNTER_COMP_ARRAY_POLARITY(ecap_cnt_pol_read, ecap_cnt_pol_write, ecap_cnt_pol_array), ··· 479 int ret; 480 481 counter_dev = devm_counter_alloc(dev, sizeof(*ecap_dev)); 482 + if (!counter_dev) 483 + return -ENOMEM; 484 485 counter_dev->name = ECAP_DRV_NAME; 486 counter_dev->parent = dev;
+2 -3
include/linux/counter.h
··· 542 #define DEFINE_COUNTER_ARRAY_CAPTURE(_name, _length) \ 543 DEFINE_COUNTER_ARRAY_U64(_name, _length) 544 545 - #define DEFINE_COUNTER_ARRAY_POLARITY(_name, _enums, _length) \ 546 - DEFINE_COUNTER_AVAILABLE(_name##_available, _enums); \ 547 struct counter_array _name = { \ 548 .type = COUNTER_COMP_SIGNAL_POLARITY, \ 549 - .avail = &(_name##_available), \ 550 .length = (_length), \ 551 } 552
··· 542 #define DEFINE_COUNTER_ARRAY_CAPTURE(_name, _length) \ 543 DEFINE_COUNTER_ARRAY_U64(_name, _length) 544 545 + #define DEFINE_COUNTER_ARRAY_POLARITY(_name, _available, _length) \ 546 struct counter_array _name = { \ 547 .type = COUNTER_COMP_SIGNAL_POLARITY, \ 548 + .avail = &(_available), \ 549 .length = (_length), \ 550 } 551