cam_common_util.c 970 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/string.h>
  6. #include <linux/types.h>
  7. #include <linux/slab.h>
  8. #include "cam_common_util.h"
  9. #include "cam_debug_util.h"
  10. int cam_common_util_get_string_index(const char **strings,
  11. uint32_t num_strings, const char *matching_string, uint32_t *index)
  12. {
  13. int i;
  14. for (i = 0; i < num_strings; i++) {
  15. if (strnstr(strings[i], matching_string, strlen(strings[i]))) {
  16. CAM_DBG(CAM_UTIL, "matched %s : %d\n",
  17. matching_string, i);
  18. *index = i;
  19. return 0;
  20. }
  21. }
  22. return -EINVAL;
  23. }
  24. uint32_t cam_common_util_remove_duplicate_arr(int32_t *arr, uint32_t num)
  25. {
  26. int i, j;
  27. uint32_t wr_idx = 1;
  28. if (!arr) {
  29. CAM_ERR(CAM_UTIL, "Null input array");
  30. return 0;
  31. }
  32. for (i = 1; i < num; i++) {
  33. for (j = 0; j < wr_idx ; j++) {
  34. if (arr[i] == arr[j])
  35. break;
  36. }
  37. if (j == wr_idx)
  38. arr[wr_idx++] = arr[i];
  39. }
  40. return wr_idx;
  41. }