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

ASoC: SOF: ipc3-control: Merge functions to handle bytes_ext get variants

The code for bytes_ext_get and bytes_ext_volatile_get is identical with
the only difference is that in case of volatile_get we refresh the data
from the DSP before returning it to user space.

Convert the callbacks to a simple wrapper for the same function.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/20230313110344.16644-3-peter.ujfalusi@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Peter Ujfalusi and committed by
Mark Brown
76fc628a 3eac8de3

+23 -57
+23 -57
sound/soc/sof/ipc3-control.c
··· 343 343 return 0; 344 344 } 345 345 346 - static int sof_ipc3_bytes_ext_get(struct snd_sof_control *scontrol, 347 - const unsigned int __user *binary_data, unsigned int size) 348 - { 349 - struct snd_ctl_tlv __user *tlvd = (struct snd_ctl_tlv __user *)binary_data; 350 - struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data; 351 - struct snd_soc_component *scomp = scontrol->scomp; 352 - struct snd_ctl_tlv header; 353 - size_t data_size; 354 - 355 - sof_ipc3_refresh_control(scontrol); 356 - 357 - /* 358 - * Decrement the limit by ext bytes header size to 359 - * ensure the user space buffer is not exceeded. 360 - */ 361 - if (size < sizeof(struct snd_ctl_tlv)) 362 - return -ENOSPC; 363 - 364 - size -= sizeof(struct snd_ctl_tlv); 365 - 366 - /* set the ABI header values */ 367 - cdata->data->magic = SOF_ABI_MAGIC; 368 - cdata->data->abi = SOF_ABI_VERSION; 369 - 370 - /* check data size doesn't exceed max coming from topology */ 371 - if (cdata->data->size > scontrol->max_size - sizeof(struct sof_abi_hdr)) { 372 - dev_err_ratelimited(scomp->dev, "User data size %d exceeds max size %zu\n", 373 - cdata->data->size, 374 - scontrol->max_size - sizeof(struct sof_abi_hdr)); 375 - return -EINVAL; 376 - } 377 - 378 - data_size = cdata->data->size + sizeof(struct sof_abi_hdr); 379 - 380 - /* make sure we don't exceed size provided by user space for data */ 381 - if (data_size > size) 382 - return -ENOSPC; 383 - 384 - header.numid = cdata->cmd; 385 - header.length = data_size; 386 - if (copy_to_user(tlvd, &header, sizeof(struct snd_ctl_tlv))) 387 - return -EFAULT; 388 - 389 - if (copy_to_user(tlvd->tlv, cdata->data, data_size)) 390 - return -EFAULT; 391 - 392 - return 0; 393 - } 394 - 395 346 static int sof_ipc3_bytes_ext_put(struct snd_sof_control *scontrol, 396 347 const unsigned int __user *binary_data, 397 348 unsigned int size) ··· 408 457 return 0; 409 458 } 410 459 411 - static int sof_ipc3_bytes_ext_volatile_get(struct snd_sof_control *scontrol, 412 - const unsigned int __user *binary_data, 413 - unsigned int size) 460 + static int _sof_ipc3_bytes_ext_get(struct snd_sof_control *scontrol, 461 + const unsigned int __user *binary_data, 462 + unsigned int size, bool from_dsp) 414 463 { 415 464 struct snd_ctl_tlv __user *tlvd = (struct snd_ctl_tlv __user *)binary_data; 416 465 struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data; 417 466 struct snd_soc_component *scomp = scontrol->scomp; 418 467 struct snd_ctl_tlv header; 419 468 size_t data_size; 420 - int ret; 421 469 422 470 /* 423 471 * Decrement the limit by ext bytes header size to ··· 432 482 cdata->data->abi = SOF_ABI_VERSION; 433 483 434 484 /* get all the component data from DSP */ 435 - ret = sof_ipc3_set_get_kcontrol_data(scontrol, false, true); 436 - if (ret < 0) 437 - return ret; 485 + if (from_dsp) { 486 + int ret = sof_ipc3_set_get_kcontrol_data(scontrol, false, true); 487 + 488 + if (ret < 0) 489 + return ret; 490 + } 438 491 439 492 /* check data size doesn't exceed max coming from topology */ 440 493 if (cdata->data->size > scontrol->max_size - sizeof(struct sof_abi_hdr)) { ··· 461 508 if (copy_to_user(tlvd->tlv, cdata->data, data_size)) 462 509 return -EFAULT; 463 510 464 - return ret; 511 + return 0; 512 + } 513 + 514 + static int sof_ipc3_bytes_ext_get(struct snd_sof_control *scontrol, 515 + const unsigned int __user *binary_data, unsigned int size) 516 + { 517 + return _sof_ipc3_bytes_ext_get(scontrol, binary_data, size, false); 518 + } 519 + 520 + static int sof_ipc3_bytes_ext_volatile_get(struct snd_sof_control *scontrol, 521 + const unsigned int __user *binary_data, 522 + unsigned int size) 523 + { 524 + return _sof_ipc3_bytes_ext_get(scontrol, binary_data, size, true); 465 525 } 466 526 467 527 static void snd_sof_update_control(struct snd_sof_control *scontrol,