Skip to contentSkip to conversation

regmap: sort header includes

PATCH In review Sander Vanheule 2 participants 3 messages Feb 20 – Feb 25 Register map abstraction

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 regmap: sort header includes

Sort the included headers to make spotting duplicates easier and avoid discussions on where to add new includes.

---
New patch since v2

---
 include/linux/regmap.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
include/linux/regmap.h +6 -6
index caff2240bdab..c8a6a05bdba1 100644
@@ -10,15 +10,15 @@
  * Author: Mark Brown <[email protected]>
  */
 
-#include <linux/list.h>
-#include <linux/rbtree.h>
-#include <linux/ktime.h>
+#include <linux/bug.h>
 #include <linux/delay.h>
 #include <linux/err.h>
-#include <linux/bug.h>
-#include <linux/lockdep.h>
-#include <linux/iopoll.h>
 #include <linux/fwnode.h>
+#include <linux/iopoll.h>
+#include <linux/ktime.h>
+#include <linux/list.h>
+#include <linux/lockdep.h>
+#include <linux/rbtree.h>
 
 struct module;
 struct clk;
Signature · 1 line
2.53.0
#1 lore raw

PATCH v2 2/2 regmap: define cleanup helper for regmap_field

For temporary field allocation, the user has to perform manual cleanup, or rely on devm_regmap_field_alloc() to (eventually) clean up the allocated resources when an error occurs.

Add a cleanup helper that takes care of freeing the allocated regmap_field whenever it goes out of scope.

This can simplify this example:

    struct regmap_field *field = regmap_field_alloc(...);
    if (IS_ERR(field))
        return PTR_ERR(field);

    int err = regmap_field_read(...);
    if (err)
        goto out;

    /* some logic that may also error */

    err = regmap_field_write(...);
  out:
    regmap_field_free(field);
    return err;

into the shorter:

    struct regmap_field *field __free(regmap_field) = regmap_field_alloc(...);
    if (IS_ERR(field))
        return PTR_ERR(field);

    int err = regmap_field_read(...);
    if (err)
        return err;

    /* some logic that may also error */

    return regmap_field_write(...);

---
Changes since v1:
- Fix error handling of regmap_field_alloc() in example
- Make example less trivial

---
 include/linux/regmap.h | 3 +++
 1 file changed, 3 insertions(+)
include/linux/regmap.h +3 -0
index c8a6a05bdba1..f1c5cb63c171 100644
@@ -11,6 +11,7 @@
  */
 
 #include <linux/bug.h>
+#include <linux/cleanup.h>
 #include <linux/delay.h>
 #include <linux/err.h>
 #include <linux/fwnode.h>
@@ -1460,6 +1461,8 @@ struct regmap_field *regmap_field_alloc(struct regmap *regmap,
 		struct reg_field reg_field);
 void regmap_field_free(struct regmap_field *field);
 
+DEFINE_FREE(regmap_field, struct regmap_field *, if (_T) regmap_field_free(_T))
+
 struct regmap_field *devm_regmap_field_alloc(struct device *dev,
 		struct regmap *regmap, struct reg_field reg_field);
 void devm_regmap_field_free(struct device *dev,	struct regmap_field *field);
Signature · 1 line
2.53.0
maintainer
#2 lore raw
In reply to Sander Vanheule
Quoted 4 lines · Sander Vanheule

Sort the included headers to make spotting duplicates easier and avoid discussions on where to add new includes.

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git for-next

Thanks!

[1/2] regmap: sort header includes

      commit: 38ab6557234d8629407a824be90e82514d6129a0
[2/2] regmap: define cleanup helper for regmap_field
      commit: 37983fad7f3ef296fa0504c8e945987459dc5487

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark