hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/base/regmap/regcache-rbtree.c
....@@ -1,14 +1,10 @@
1
-/*
2
- * Register cache access API - rbtree caching support
3
- *
4
- * Copyright 2011 Wolfson Microelectronics plc
5
- *
6
- * Author: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License version 2 as
10
- * published by the Free Software Foundation.
11
- */
1
+// SPDX-License-Identifier: GPL-2.0
2
+//
3
+// Register cache access API - rbtree caching support
4
+//
5
+// Copyright 2011 Wolfson Microelectronics plc
6
+//
7
+// Author: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
128
139 #include <linux/debugfs.h>
1410 #include <linux/device.h>
....@@ -33,7 +29,7 @@
3329 unsigned int blklen;
3430 /* the actual rbtree node holding this block */
3531 struct rb_node node;
36
-} __attribute__ ((packed));
32
+};
3733
3834 struct regcache_rbtree_ctx {
3935 struct rb_root root;
....@@ -177,17 +173,7 @@
177173 return 0;
178174 }
179175
180
-static int rbtree_open(struct inode *inode, struct file *file)
181
-{
182
- return single_open(file, rbtree_show, inode->i_private);
183
-}
184
-
185
-static const struct file_operations rbtree_fops = {
186
- .open = rbtree_open,
187
- .read = seq_read,
188
- .llseek = seq_lseek,
189
- .release = single_release,
190
-};
176
+DEFINE_SHOW_ATTRIBUTE(rbtree);
191177
192178 static void rbtree_debugfs_init(struct regmap *map)
193179 {
....@@ -291,7 +277,7 @@
291277
292278 blk = krealloc(rbnode->block,
293279 blklen * map->cache_word_size,
294
- GFP_KERNEL);
280
+ map->alloc_flags);
295281 if (!blk)
296282 return -ENOMEM;
297283
....@@ -300,7 +286,7 @@
300286 if (BITS_TO_LONGS(blklen) > BITS_TO_LONGS(rbnode->blklen)) {
301287 present = krealloc(rbnode->cache_present,
302288 BITS_TO_LONGS(blklen) * sizeof(*present),
303
- GFP_KERNEL);
289
+ map->alloc_flags);
304290 if (!present)
305291 return -ENOMEM;
306292
....@@ -334,7 +320,7 @@
334320 const struct regmap_range *range;
335321 int i;
336322
337
- rbnode = kzalloc(sizeof(*rbnode), GFP_KERNEL);
323
+ rbnode = kzalloc(sizeof(*rbnode), map->alloc_flags);
338324 if (!rbnode)
339325 return NULL;
340326
....@@ -360,13 +346,13 @@
360346 }
361347
362348 rbnode->block = kmalloc_array(rbnode->blklen, map->cache_word_size,
363
- GFP_KERNEL);
349
+ map->alloc_flags);
364350 if (!rbnode->block)
365351 goto err_free;
366352
367353 rbnode->cache_present = kcalloc(BITS_TO_LONGS(rbnode->blklen),
368354 sizeof(*rbnode->cache_present),
369
- GFP_KERNEL);
355
+ map->alloc_flags);
370356 if (!rbnode->cache_present)
371357 goto err_free_block;
372358
....@@ -467,7 +453,8 @@
467453 if (!rbnode)
468454 return -ENOMEM;
469455 regcache_rbtree_set_register(map, rbnode,
470
- reg - rbnode->base_reg, value);
456
+ (reg - rbnode->base_reg) / map->reg_stride,
457
+ value);
471458 regcache_rbtree_insert(map, &rbtree_ctx->root, rbnode);
472459 rbtree_ctx->cached_rbnode = rbnode;
473460 }