@@ -358,15 +358,20 @@ static int scmi_sensor_update_intervals(const struct scmi_protocol_handle *ph,
358358 return ph -> hops -> iter_response_run (iter );
359359}
360360
361+ struct scmi_apriv {
362+ bool any_axes_support_extended_names ;
363+ struct scmi_sensor_info * s ;
364+ };
365+
361366static void iter_axes_desc_prepare_message (void * message ,
362367 const unsigned int desc_index ,
363368 const void * priv )
364369{
365370 struct scmi_msg_sensor_axis_description_get * msg = message ;
366- const struct scmi_sensor_info * s = priv ;
371+ const struct scmi_apriv * apriv = priv ;
367372
368373 /* Set the number of sensors to be skipped/already read */
369- msg -> id = cpu_to_le32 (s -> id );
374+ msg -> id = cpu_to_le32 (apriv -> s -> id );
370375 msg -> axis_desc_index = cpu_to_le32 (desc_index );
371376}
372377
@@ -393,12 +398,14 @@ iter_axes_desc_process_response(const struct scmi_protocol_handle *ph,
393398 u32 attrh , attrl ;
394399 struct scmi_sensor_axis_info * a ;
395400 size_t dsize = SCMI_MSG_RESP_AXIS_DESCR_BASE_SZ ;
396- struct scmi_sensor_info * s = priv ;
401+ struct scmi_apriv * apriv = priv ;
397402 const struct scmi_axis_descriptor * adesc = st -> priv ;
398403
399404 attrl = le32_to_cpu (adesc -> attributes_low );
405+ if (SUPPORTS_EXTENDED_AXIS_NAMES (attrl ))
406+ apriv -> any_axes_support_extended_names = true;
400407
401- a = & s -> axis [st -> desc_index + st -> loop_idx ];
408+ a = & apriv -> s -> axis [st -> desc_index + st -> loop_idx ];
402409 a -> id = le32_to_cpu (adesc -> id );
403410 a -> extended_attrs = SUPPORTS_EXTEND_ATTRS (attrl );
404411
@@ -444,10 +451,19 @@ iter_axes_extended_name_process_response(const struct scmi_protocol_handle *ph,
444451 void * priv )
445452{
446453 struct scmi_sensor_axis_info * a ;
447- const struct scmi_sensor_info * s = priv ;
454+ const struct scmi_apriv * apriv = priv ;
448455 struct scmi_sensor_axis_name_descriptor * adesc = st -> priv ;
456+ u32 axis_id = le32_to_cpu (adesc -> axis_id );
457+
458+ if (axis_id >= st -> max_resources )
459+ return - EPROTO ;
449460
450- a = & s -> axis [st -> desc_index + st -> loop_idx ];
461+ /*
462+ * Pick the corresponding descriptor based on the axis_id embedded
463+ * in the reply since the list of axes supporting extended names
464+ * can be a subset of all the axes.
465+ */
466+ a = & apriv -> s -> axis [axis_id ];
451467 strscpy (a -> name , adesc -> name , SCMI_MAX_STR_SIZE );
452468 st -> priv = ++ adesc ;
453469
@@ -458,21 +474,36 @@ static int
458474scmi_sensor_axis_extended_names_get (const struct scmi_protocol_handle * ph ,
459475 struct scmi_sensor_info * s )
460476{
477+ int ret ;
461478 void * iter ;
462479 struct scmi_iterator_ops ops = {
463480 .prepare_message = iter_axes_desc_prepare_message ,
464481 .update_state = iter_axes_extended_name_update_state ,
465482 .process_response = iter_axes_extended_name_process_response ,
466483 };
484+ struct scmi_apriv apriv = {
485+ .any_axes_support_extended_names = false,
486+ .s = s ,
487+ };
467488
468489 iter = ph -> hops -> iter_response_init (ph , & ops , s -> num_axis ,
469490 SENSOR_AXIS_NAME_GET ,
470491 sizeof (struct scmi_msg_sensor_axis_description_get ),
471- s );
492+ & apriv );
472493 if (IS_ERR (iter ))
473494 return PTR_ERR (iter );
474495
475- return ph -> hops -> iter_response_run (iter );
496+ /*
497+ * Do not cause whole protocol initialization failure when failing to
498+ * get extended names for axes.
499+ */
500+ ret = ph -> hops -> iter_response_run (iter );
501+ if (ret )
502+ dev_warn (ph -> dev ,
503+ "Failed to get axes extended names for %s (ret:%d).\n" ,
504+ s -> name , ret );
505+
506+ return 0 ;
476507}
477508
478509static int scmi_sensor_axis_description (const struct scmi_protocol_handle * ph ,
@@ -486,6 +517,10 @@ static int scmi_sensor_axis_description(const struct scmi_protocol_handle *ph,
486517 .update_state = iter_axes_desc_update_state ,
487518 .process_response = iter_axes_desc_process_response ,
488519 };
520+ struct scmi_apriv apriv = {
521+ .any_axes_support_extended_names = false,
522+ .s = s ,
523+ };
489524
490525 s -> axis = devm_kcalloc (ph -> dev , s -> num_axis ,
491526 sizeof (* s -> axis ), GFP_KERNEL );
@@ -495,15 +530,16 @@ static int scmi_sensor_axis_description(const struct scmi_protocol_handle *ph,
495530 iter = ph -> hops -> iter_response_init (ph , & ops , s -> num_axis ,
496531 SENSOR_AXIS_DESCRIPTION_GET ,
497532 sizeof (struct scmi_msg_sensor_axis_description_get ),
498- s );
533+ & apriv );
499534 if (IS_ERR (iter ))
500535 return PTR_ERR (iter );
501536
502537 ret = ph -> hops -> iter_response_run (iter );
503538 if (ret )
504539 return ret ;
505540
506- if (PROTOCOL_REV_MAJOR (version ) >= 0x3 )
541+ if (PROTOCOL_REV_MAJOR (version ) >= 0x3 &&
542+ apriv .any_axes_support_extended_names )
507543 ret = scmi_sensor_axis_extended_names_get (ph , s );
508544
509545 return ret ;
0 commit comments