Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 2 | #include "xyarray.h" |
Arnaldo Carvalho de Melo | 72f7c4d | 2017-04-19 19:06:30 -0300 | [diff] [blame] | 3 | #include <stdlib.h> |
| 4 | #include <string.h> |
Arnaldo Carvalho de Melo | 7f7c536 | 2019-07-04 11:32:27 -0300 | [diff] [blame] | 5 | #include <linux/zalloc.h> |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 6 | |
| 7 | struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size) |
| 8 | { |
| 9 | size_t row_size = ylen * entry_size; |
| 10 | struct xyarray *xy = zalloc(sizeof(*xy) + xlen * row_size); |
| 11 | |
| 12 | if (xy != NULL) { |
| 13 | xy->entry_size = entry_size; |
| 14 | xy->row_size = row_size; |
Jiri Olsa | b45f65e | 2015-06-14 10:19:16 +0200 | [diff] [blame] | 15 | xy->entries = xlen * ylen; |
Andi Kleen | d74be47 | 2017-08-11 16:26:16 -0700 | [diff] [blame] | 16 | xy->max_x = xlen; |
| 17 | xy->max_y = ylen; |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | return xy; |
| 21 | } |
| 22 | |
Jiri Olsa | b45f65e | 2015-06-14 10:19:16 +0200 | [diff] [blame] | 23 | void xyarray__reset(struct xyarray *xy) |
| 24 | { |
| 25 | size_t n = xy->entries * xy->entry_size; |
| 26 | |
| 27 | memset(xy->contents, 0, n); |
| 28 | } |
| 29 | |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 30 | void xyarray__delete(struct xyarray *xy) |
| 31 | { |
| 32 | free(xy); |
| 33 | } |