From patchwork Fri Jun 26 16:55:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 11628065 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 387DC618 for ; Fri, 26 Jun 2020 16:56:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1F1E9207FC for ; Fri, 26 Jun 2020 16:56:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="ODf1qLrK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727066AbgFZQ4Q (ORCPT ); Fri, 26 Jun 2020 12:56:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727053AbgFZQzz (ORCPT ); Fri, 26 Jun 2020 12:55:55 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D8FCC03E97B for ; Fri, 26 Jun 2020 09:55:55 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id t194so10003902wmt.4 for ; Fri, 26 Jun 2020 09:55:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YrSMqNfBoEk4+fX9YqI78/jZTXRW6ktfo7V3K+aMn3w=; b=ODf1qLrK8C75l4csBNa28ShD2JvP1VITfSbkol/mVz4l/Nggp0Bxu6tin/T4einR+F 1Z809a2zXScu/dFsu3KwXrr8dkzFIoAenoEijF3R7CS3+ypa58d+FALuxPB/SnrY8CFJ BFMhNFF6borMmZhhnoZEqjF44Hv/xogMioRbNSvLTA0ICZSgmqDCEczzilXj9D4jVWFK ZcliQXe5SKPXTncj2Az/MxXb96+bZyW/olb2g3v3fna5IiBXGSETTuBcHLriV4BRwZW4 tgmO1Vkfaurtx39hQiuXuX8RxrMFg93pzH9AcwbOkogpSkwHmWpCIOfx1u3mGRk4t/KX k5ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YrSMqNfBoEk4+fX9YqI78/jZTXRW6ktfo7V3K+aMn3w=; b=tTh1lDrgcQdLdwbo0qW7LApjHNpXXdd+cVD74bCPQD+cNsOZKFLwimO9Klh0Sd9fOB TQoJwnv1N702dvbUYZpKQol+uQKq3036PHtMiUdwca/Oj3mUDOTQhcEOU8KmzeVmCvac 1UGhnDJyXvlRKEwbwNYPm0Ll94jYviKrrleLaQZx5Xh3efp3MkfrC4QlH/hWX7hlF+Hd l9I0N2bEGdMMdNvx28du5OJD0txiGJqWzRVr4KN0FXVhQuJmWTtWNrRR+uA4/2bwVKPV keGDiHfk4UgJqDupuI26EvlSEhL7rvIdQZ3+MkXQ62xRvgh2uEbuYuKwoiQuC81H7IwE h/6A== X-Gm-Message-State: AOAM53365Anojj4YmqzRsS2Y8HF3DmAAMv1ijLU/1k1/hRqNMYQqoDUF dcc0IKSNeDIZtDu6lyob4V2POw== X-Google-Smtp-Source: ABdhPJywW9EslIlEG4xGnIIz/FnNGMv7QXiKTP/zXruJmAodeLhm9p3zq3POFS/SVYW2Jb5B4tPX4A== X-Received: by 2002:a05:600c:2317:: with SMTP id 23mr4569316wmo.72.1593190553746; Fri, 26 Jun 2020 09:55:53 -0700 (PDT) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id x5sm18654706wmg.2.2020.06.26.09.55.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 09:55:53 -0700 (PDT) From: Bartosz Golaszewski To: Jonathan Corbet , Greg Kroah-Hartman , "Rafael J . Wysocki" , Guenter Roeck , Jean Delvare Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 1/5] devres: remove stray space from devm_kmalloc() definition Date: Fri, 26 Jun 2020 18:55:31 +0200 Message-Id: <20200626165535.7662-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200626165535.7662-1-brgl@bgdev.pl> References: <20200626165535.7662-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Bartosz Golaszewski Use the preferred coding style for functions returning pointers. Signed-off-by: Bartosz Golaszewski --- drivers/base/devres.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/base/devres.c b/drivers/base/devres.c index 0bbb328bd17f..c34327219c34 100644 --- a/drivers/base/devres.c +++ b/drivers/base/devres.c @@ -807,7 +807,7 @@ static int devm_kmalloc_match(struct device *dev, void *res, void *data) * RETURNS: * Pointer to allocated memory on success, NULL on failure. */ -void * devm_kmalloc(struct device *dev, size_t size, gfp_t gfp) +void *devm_kmalloc(struct device *dev, size_t size, gfp_t gfp) { struct devres *dr; From patchwork Fri Jun 26 16:55:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 11628057 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E2BCC618 for ; Fri, 26 Jun 2020 16:55:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CA9692081A for ; Fri, 26 Jun 2020 16:55:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="pLjENJni" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728049AbgFZQz5 (ORCPT ); Fri, 26 Jun 2020 12:55:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727999AbgFZQz4 (ORCPT ); Fri, 26 Jun 2020 12:55:56 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E58BC03E97E for ; Fri, 26 Jun 2020 09:55:56 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id t194so10003980wmt.4 for ; Fri, 26 Jun 2020 09:55:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/lPkRY5zqjvg98KXV/ewwSSeHltl7MZJ65glZzN0dPQ=; b=pLjENJnipeX3viAS4oiwGwHuQxp+luxXZFGZNsk1Sebe+55YK89RfjyoqCEKXJitDd YXYUYb3XLd9ZDmYALGMwa8TWbueR6z6aF/OopHNtymeQR9ejUEvzisKPw7GcbVhVuOsi MUZ/dh/7IIJ9GD7K8KpZf/5xUtGUnq9ZV8hBt4XmxENUJF/2OBLINttSSpIjG9CqwuA2 8raCwfevgitmS+cwaxCB7BRGADKtJMm9BXsrC3fJKhwfxo3T1mdTX12ko/nGX/r1Bdz4 xgJe/d0jzWZA1edu+NZ/nHI+ijq/TIAoznbHKixq+PLEB4nLXz+o3yObJczwYPrmLjmN +vxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/lPkRY5zqjvg98KXV/ewwSSeHltl7MZJ65glZzN0dPQ=; b=YD3MFyiVFfNvv6n08e1cBz8WKXXDriSVJIt59mOePi8GvpU5GTUHepQQwtpR++CuLp QVuEsAGHz3S2CRJp9p7spho/OzeeaOm8HAJVyLdtmmRMs++Pwp/Rrg9McNG5KFxuK3zM KcdlH6S3q131GaGPjhKooL+SkP6jOUsFpy5KR15kvKCsvp0Uw6a2JdGLw+2wMirgqKpS NQF8eSdOPz/sxJBziZdDHeqw/OPYnkpLeO4NRDIneudq1OHGdgxckJEj/DnuQwigEn4z NQupo6lUTUiNCql2VIUS3hiLPidJ+8p3ldhLm7o7oYTA9ljNZyxonrPUw8g+//IC4ww8 HWpA== X-Gm-Message-State: AOAM531WqWCGEajqNchXqwE7SBuK2sEsKDo9njt1Pxnz0iMfVSSLo0dl 7b7PLhWCCqZR6E5gMLwSM5vWAWztW58= X-Google-Smtp-Source: ABdhPJyxOs5CR2+PSateKUw0zxt3VRMZK9JAKGI+K8Yv+vIR129kqzmxqJ60onO4gKykLo9nuvF2Fw== X-Received: by 2002:a1c:6102:: with SMTP id v2mr4539558wmb.6.1593190554931; Fri, 26 Jun 2020 09:55:54 -0700 (PDT) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id x5sm18654706wmg.2.2020.06.26.09.55.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 09:55:54 -0700 (PDT) From: Bartosz Golaszewski To: Jonathan Corbet , Greg Kroah-Hartman , "Rafael J . Wysocki" , Guenter Roeck , Jean Delvare Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 2/5] devres: move the size check from alloc_dr() into a separate function Date: Fri, 26 Jun 2020 18:55:32 +0200 Message-Id: <20200626165535.7662-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200626165535.7662-1-brgl@bgdev.pl> References: <20200626165535.7662-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Bartosz Golaszewski We will perform the same size check in devm_krealloc(). Move the relevant code into a separate helper. Signed-off-by: Bartosz Golaszewski --- drivers/base/devres.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/base/devres.c b/drivers/base/devres.c index c34327219c34..1df1fb10b2d9 100644 --- a/drivers/base/devres.c +++ b/drivers/base/devres.c @@ -89,15 +89,23 @@ static struct devres_group * node_to_group(struct devres_node *node) return NULL; } +static bool check_dr_size(size_t size, size_t *tot_size) +{ + /* We must catch any near-SIZE_MAX cases that could overflow. */ + if (unlikely(check_add_overflow(sizeof(struct devres), + size, tot_size))) + return false; + + return true; +} + static __always_inline struct devres * alloc_dr(dr_release_t release, size_t size, gfp_t gfp, int nid) { size_t tot_size; struct devres *dr; - /* We must catch any near-SIZE_MAX cases that could overflow. */ - if (unlikely(check_add_overflow(sizeof(struct devres), size, - &tot_size))) + if (!check_dr_size(size, &tot_size)) return NULL; dr = kmalloc_node_track_caller(tot_size, gfp, nid); From patchwork Fri Jun 26 16:55:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 11628063 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BD53092A for ; Fri, 26 Jun 2020 16:56:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 96066207FC for ; Fri, 26 Jun 2020 16:56:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="OpUCbFBh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728181AbgFZQ4O (ORCPT ); Fri, 26 Jun 2020 12:56:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728062AbgFZQz6 (ORCPT ); Fri, 26 Jun 2020 12:55:58 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A78EC03E97B for ; Fri, 26 Jun 2020 09:55:57 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id o11so10147253wrv.9 for ; Fri, 26 Jun 2020 09:55:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JYdvmIA/aO0yqwl/SsgbqDwolR2EZeVR55s8HYWjZ70=; b=OpUCbFBhiGH7kaujGtqpq8GHXSRYNOVZb/6lPfKFKLNx0JnGez73Kdq8pfbAlaKXAL 21c9uV86CX+uhBMokRHmnRza9SVtVWwR6BVLn/2LrdET6J5nnuVv4jgXWdeZa1SDlNTg lU9Zi2+CDHBhQIZQw/7Ym537WuxH+QhVMEhY7P4Czrvy281df2ho4WALhVzdxLYF5ekE jSA3JCHM2TFRRlg5WWQSFmCbbFv50zxe9phmsRxdzU1RnKnbuUxcYlG/cEc2XZl1Y8vb ZBn+7nFDgCEpfpOl+WQgE0NUuGgwB4ek0nCpBYZo0uZN/irJ19r4/uxz7STC/+ebbwPQ fiTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JYdvmIA/aO0yqwl/SsgbqDwolR2EZeVR55s8HYWjZ70=; b=sElUCb9oNIy4aH3qWQg11+d8SGPQUJacLL8dyAZLad6AgF8yFZ+anXaAAb7ekiIWF9 L6sEIeJxpzPosskGRsRpeXYYLNCWMC/QUKge/kdv53zWRAWKyOzV2CAZeG9rRVASzsAj AmYJbZDuTRrMq9lLOeqkShiko7LCnV5AO9C38YjGq4A7atBcFoUdZubNKdlOzRpl7qnH gtYBex+IUeYvuqmUtwXS0H6w6z3vgrg+9Lhvrm36SemkA4G5WLAQE010f/mPO/quRKxw 6ER9R7eZtTHXJ72WwT5ftg25axBPl4fOLgWwQHfwfstA9oimIg5KyEMYK73W1Zx7N60s BklA== X-Gm-Message-State: AOAM531k5OhXNJNSCLr6Pmm5do4KH5/rQTjgT6maXQuzDspcwgEei95o +Fr55ctk7+iPdR0b8soLMaIPGw== X-Google-Smtp-Source: ABdhPJzQ367bBxzS7A+IqTkRSV3liZfZZh6qJWLatAiVOPQ3LQ7WslM1Wumo4wMSW4ljB82iPw8DrA== X-Received: by 2002:a5d:5490:: with SMTP id h16mr5015456wrv.394.1593190556170; Fri, 26 Jun 2020 09:55:56 -0700 (PDT) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id x5sm18654706wmg.2.2020.06.26.09.55.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 09:55:55 -0700 (PDT) From: Bartosz Golaszewski To: Jonathan Corbet , Greg Kroah-Hartman , "Rafael J . Wysocki" , Guenter Roeck , Jean Delvare Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 3/5] device: remove 'extern' attribute from function prototypes in device.h Date: Fri, 26 Jun 2020 18:55:33 +0200 Message-Id: <20200626165535.7662-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200626165535.7662-1-brgl@bgdev.pl> References: <20200626165535.7662-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Bartosz Golaszewski Functions are declared 'extern' implicitly by the compiler. There's no reason to prepend every prototype with it. Remove the 'extern' keyword from all function declarations in linux/device.h. Signed-off-by: Bartosz Golaszewski --- include/linux/device.h | 223 ++++++++++++++++++++--------------------- 1 file changed, 107 insertions(+), 116 deletions(-) diff --git a/include/linux/device.h b/include/linux/device.h index 15460a5ac024..9cadb647cacc 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -145,68 +145,66 @@ ssize_t device_store_bool(struct device *dev, struct device_attribute *attr, struct device_attribute dev_attr_##_name = \ __ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) -extern int device_create_file(struct device *device, - const struct device_attribute *entry); -extern void device_remove_file(struct device *dev, - const struct device_attribute *attr); -extern bool device_remove_file_self(struct device *dev, - const struct device_attribute *attr); -extern int __must_check device_create_bin_file(struct device *dev, +int device_create_file(struct device *device, + const struct device_attribute *entry); +void device_remove_file(struct device *dev, + const struct device_attribute *attr); +bool device_remove_file_self(struct device *dev, + const struct device_attribute *attr); +int __must_check device_create_bin_file(struct device *dev, const struct bin_attribute *attr); -extern void device_remove_bin_file(struct device *dev, - const struct bin_attribute *attr); +void device_remove_bin_file(struct device *dev, + const struct bin_attribute *attr); /* device resource management */ typedef void (*dr_release_t)(struct device *dev, void *res); typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data); #ifdef CONFIG_DEBUG_DEVRES -extern void *__devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp, - int nid, const char *name) __malloc; +void *__devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp, + int nid, const char *name) __malloc; #define devres_alloc(release, size, gfp) \ __devres_alloc_node(release, size, gfp, NUMA_NO_NODE, #release) #define devres_alloc_node(release, size, gfp, nid) \ __devres_alloc_node(release, size, gfp, nid, #release) #else -extern void *devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp, - int nid) __malloc; +void *devres_alloc_node(dr_release_t release, size_t size, + gfp_t gfp, int nid) __malloc; static inline void *devres_alloc(dr_release_t release, size_t size, gfp_t gfp) { return devres_alloc_node(release, size, gfp, NUMA_NO_NODE); } #endif -extern void devres_for_each_res(struct device *dev, dr_release_t release, - dr_match_t match, void *match_data, - void (*fn)(struct device *, void *, void *), - void *data); -extern void devres_free(void *res); -extern void devres_add(struct device *dev, void *res); -extern void *devres_find(struct device *dev, dr_release_t release, - dr_match_t match, void *match_data); -extern void *devres_get(struct device *dev, void *new_res, - dr_match_t match, void *match_data); -extern void *devres_remove(struct device *dev, dr_release_t release, - dr_match_t match, void *match_data); -extern int devres_destroy(struct device *dev, dr_release_t release, - dr_match_t match, void *match_data); -extern int devres_release(struct device *dev, dr_release_t release, - dr_match_t match, void *match_data); +void devres_for_each_res(struct device *dev, dr_release_t release, + dr_match_t match, void *match_data, + void (*fn)(struct device *, void *, void *), + void *data); +void devres_free(void *res); +void devres_add(struct device *dev, void *res); +void *devres_find(struct device *dev, dr_release_t release, + dr_match_t match, void *match_data); +void *devres_get(struct device *dev, void *new_res, + dr_match_t match, void *match_data); +void *devres_remove(struct device *dev, dr_release_t release, + dr_match_t match, void *match_data); +int devres_destroy(struct device *dev, dr_release_t release, + dr_match_t match, void *match_data); +int devres_release(struct device *dev, dr_release_t release, + dr_match_t match, void *match_data); /* devres group */ -extern void * __must_check devres_open_group(struct device *dev, void *id, - gfp_t gfp); -extern void devres_close_group(struct device *dev, void *id); -extern void devres_remove_group(struct device *dev, void *id); -extern int devres_release_group(struct device *dev, void *id); +void * __must_check devres_open_group(struct device *dev, void *id, gfp_t gfp); +void devres_close_group(struct device *dev, void *id); +void devres_remove_group(struct device *dev, void *id); +int devres_release_group(struct device *dev, void *id); /* managed devm_k.alloc/kfree for device drivers */ -extern void *devm_kmalloc(struct device *dev, size_t size, gfp_t gfp) __malloc; -extern __printf(3, 0) -char *devm_kvasprintf(struct device *dev, gfp_t gfp, const char *fmt, - va_list ap) __malloc; -extern __printf(3, 4) -char *devm_kasprintf(struct device *dev, gfp_t gfp, const char *fmt, ...) __malloc; +void *devm_kmalloc(struct device *dev, size_t size, gfp_t gfp) __malloc; +__printf(3, 0) char *devm_kvasprintf(struct device *dev, gfp_t gfp, + const char *fmt, va_list ap) __malloc; +__printf(3, 4) char *devm_kasprintf(struct device *dev, gfp_t gfp, + const char *fmt, ...) __malloc; static inline void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp) { return devm_kmalloc(dev, size, gfp | __GFP_ZERO); @@ -226,16 +224,14 @@ static inline void *devm_kcalloc(struct device *dev, { return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO); } -extern void devm_kfree(struct device *dev, const void *p); -extern char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc; -extern const char *devm_kstrdup_const(struct device *dev, - const char *s, gfp_t gfp); -extern void *devm_kmemdup(struct device *dev, const void *src, size_t len, - gfp_t gfp); +void devm_kfree(struct device *dev, const void *p); +char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc; +const char *devm_kstrdup_const(struct device *dev, const char *s, gfp_t gfp); +void *devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp); -extern unsigned long devm_get_free_pages(struct device *dev, - gfp_t gfp_mask, unsigned int order); -extern void devm_free_pages(struct device *dev, unsigned long addr); +unsigned long devm_get_free_pages(struct device *dev, + gfp_t gfp_mask, unsigned int order); +void devm_free_pages(struct device *dev, unsigned long addr); void __iomem *devm_ioremap_resource(struct device *dev, const struct resource *res); @@ -651,8 +647,7 @@ static inline const char *dev_name(const struct device *dev) return kobject_name(&dev->kobj); } -extern __printf(2, 3) -int dev_set_name(struct device *dev, const char *name, ...); +__printf(2, 3) int dev_set_name(struct device *dev, const char *name, ...); #ifdef CONFIG_NUMA static inline int dev_to_node(struct device *dev) @@ -809,39 +804,38 @@ static inline bool dev_has_sync_state(struct device *dev) /* * High level routines for use by the bus drivers */ -extern int __must_check device_register(struct device *dev); -extern void device_unregister(struct device *dev); -extern void device_initialize(struct device *dev); -extern int __must_check device_add(struct device *dev); -extern void device_del(struct device *dev); -extern int device_for_each_child(struct device *dev, void *data, - int (*fn)(struct device *dev, void *data)); -extern int device_for_each_child_reverse(struct device *dev, void *data, - int (*fn)(struct device *dev, void *data)); -extern struct device *device_find_child(struct device *dev, void *data, - int (*match)(struct device *dev, void *data)); -extern struct device *device_find_child_by_name(struct device *parent, - const char *name); -extern int device_rename(struct device *dev, const char *new_name); -extern int device_move(struct device *dev, struct device *new_parent, - enum dpm_order dpm_order); -extern int device_change_owner(struct device *dev, kuid_t kuid, kgid_t kgid); -extern const char *device_get_devnode(struct device *dev, - umode_t *mode, kuid_t *uid, kgid_t *gid, - const char **tmp); +int __must_check device_register(struct device *dev); +void device_unregister(struct device *dev); +void device_initialize(struct device *dev); +int __must_check device_add(struct device *dev); +void device_del(struct device *dev); +int device_for_each_child(struct device *dev, void *data, + int (*fn)(struct device *dev, void *data)); +int device_for_each_child_reverse(struct device *dev, void *data, + int (*fn)(struct device *dev, void *data)); +struct device *device_find_child(struct device *dev, void *data, + int (*match)(struct device *dev, void *data)); +struct device *device_find_child_by_name(struct device *parent, + const char *name); +int device_rename(struct device *dev, const char *new_name); +int device_move(struct device *dev, struct device *new_parent, + enum dpm_order dpm_order); +int device_change_owner(struct device *dev, kuid_t kuid, kgid_t kgid); +const char *device_get_devnode(struct device *dev, umode_t *mode, kuid_t *uid, + kgid_t *gid, const char **tmp); static inline bool device_supports_offline(struct device *dev) { return dev->bus && dev->bus->offline && dev->bus->online; } -extern void lock_device_hotplug(void); -extern void unlock_device_hotplug(void); -extern int lock_device_hotplug_sysfs(void); -extern int device_offline(struct device *dev); -extern int device_online(struct device *dev); -extern void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode); -extern void set_secondary_fwnode(struct device *dev, struct fwnode_handle *fwnode); +void lock_device_hotplug(void); +void unlock_device_hotplug(void); +int lock_device_hotplug_sysfs(void); +int device_offline(struct device *dev); +int device_online(struct device *dev); +void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode); +void set_secondary_fwnode(struct device *dev, struct fwnode_handle *fwnode); void device_set_of_node_from_dev(struct device *dev, const struct device *dev2); static inline int dev_num_vf(struct device *dev) @@ -854,14 +848,13 @@ static inline int dev_num_vf(struct device *dev) /* * Root device objects for grouping under /sys/devices */ -extern struct device *__root_device_register(const char *name, - struct module *owner); +struct device *__root_device_register(const char *name, struct module *owner); /* This is a macro to avoid include problems with THIS_MODULE */ #define root_device_register(name) \ __root_device_register(name, THIS_MODULE) -extern void root_device_unregister(struct device *root); +void root_device_unregister(struct device *root); static inline void *dev_get_platdata(const struct device *dev) { @@ -872,33 +865,31 @@ static inline void *dev_get_platdata(const struct device *dev) * Manual binding of a device to driver. See drivers/base/bus.c * for information on use. */ -extern int __must_check device_bind_driver(struct device *dev); -extern void device_release_driver(struct device *dev); -extern int __must_check device_attach(struct device *dev); -extern int __must_check driver_attach(struct device_driver *drv); -extern void device_initial_probe(struct device *dev); -extern int __must_check device_reprobe(struct device *dev); +int __must_check device_bind_driver(struct device *dev); +void device_release_driver(struct device *dev); +int __must_check device_attach(struct device *dev); +int __must_check driver_attach(struct device_driver *drv); +void device_initial_probe(struct device *dev); +int __must_check device_reprobe(struct device *dev); -extern bool device_is_bound(struct device *dev); +bool device_is_bound(struct device *dev); /* * Easy functions for dynamically creating devices on the fly */ -extern __printf(5, 6) -struct device *device_create(struct class *cls, struct device *parent, - dev_t devt, void *drvdata, - const char *fmt, ...); -extern __printf(6, 7) -struct device *device_create_with_groups(struct class *cls, - struct device *parent, dev_t devt, void *drvdata, - const struct attribute_group **groups, - const char *fmt, ...); -extern void device_destroy(struct class *cls, dev_t devt); - -extern int __must_check device_add_groups(struct device *dev, - const struct attribute_group **groups); -extern void device_remove_groups(struct device *dev, - const struct attribute_group **groups); +__printf(5, 6) struct device * +device_create(struct class *cls, struct device *parent, dev_t devt, + void *drvdata, const char *fmt, ...); +__printf(6, 7) struct device * +device_create_with_groups(struct class *cls, struct device *parent, dev_t devt, + void *drvdata, const struct attribute_group **groups, + const char *fmt, ...); +void device_destroy(struct class *cls, dev_t devt); + +int __must_check device_add_groups(struct device *dev, + const struct attribute_group **groups); +void device_remove_groups(struct device *dev, + const struct attribute_group **groups); static inline int __must_check device_add_group(struct device *dev, const struct attribute_group *grp) @@ -916,14 +907,14 @@ static inline void device_remove_group(struct device *dev, return device_remove_groups(dev, groups); } -extern int __must_check devm_device_add_groups(struct device *dev, +int __must_check devm_device_add_groups(struct device *dev, const struct attribute_group **groups); -extern void devm_device_remove_groups(struct device *dev, - const struct attribute_group **groups); -extern int __must_check devm_device_add_group(struct device *dev, - const struct attribute_group *grp); -extern void devm_device_remove_group(struct device *dev, - const struct attribute_group *grp); +void devm_device_remove_groups(struct device *dev, + const struct attribute_group **groups); +int __must_check devm_device_add_group(struct device *dev, + const struct attribute_group *grp); +void devm_device_remove_group(struct device *dev, + const struct attribute_group *grp); /* * Platform "fixup" functions - allow the platform to have their say @@ -940,21 +931,21 @@ extern int (*platform_notify_remove)(struct device *dev); * get_device - atomically increment the reference count for the device. * */ -extern struct device *get_device(struct device *dev); -extern void put_device(struct device *dev); -extern bool kill_device(struct device *dev); +struct device *get_device(struct device *dev); +void put_device(struct device *dev); +bool kill_device(struct device *dev); #ifdef CONFIG_DEVTMPFS -extern int devtmpfs_mount(void); +int devtmpfs_mount(void); #else static inline int devtmpfs_mount(void) { return 0; } #endif /* drivers/base/power/shutdown.c */ -extern void device_shutdown(void); +void device_shutdown(void); /* debugging and troubleshooting/diagnostic helpers. */ -extern const char *dev_driver_string(const struct device *dev); +const char *dev_driver_string(const struct device *dev); /* Device links interface. */ struct device_link *device_link_add(struct device *consumer, From patchwork Fri Jun 26 16:55:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 11628061 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1370F161F for ; Fri, 26 Jun 2020 16:56:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E78E9206BE for ; Fri, 26 Jun 2020 16:56:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="P8OISsXa" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728126AbgFZQ4J (ORCPT ); Fri, 26 Jun 2020 12:56:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728096AbgFZQz7 (ORCPT ); Fri, 26 Jun 2020 12:55:59 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9075C08C5DB for ; Fri, 26 Jun 2020 09:55:58 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id q5so10146321wru.6 for ; Fri, 26 Jun 2020 09:55:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XwLPHUiUd7u8i6DlgTqpUvjVOFN4vpyWhbccIRdmj5g=; b=P8OISsXa/l4EX27H6DX2GeRuI7OsQIMd2NP+uFFYiaautFiYCDjrQ/jnPipqUwr1mt uFC8WZaN3b1HYPWEXLjvO42FShpnGs/xqt70CjD7VuO4w33auwI6QzJuWPxsMqio/7Dd BGkv68viVX1g5PHlqiE0GA/8pmJ6KfG6TUbI92TYy6io+WwM7LLm4Q6BZbxd3IJu+fdM v/qdKZRhFJLU5LM6Fw5tiKfF7pYjBDJNHJBnD4oAYw8+m4MO+Z66auejVSVaOtkpGSxL mdXHbU9+cH+nw2X6tmTG0RuCHf/VAoLIcdPKJyqtZZuIOSx09/h1EB0eYthkNiO6TOr9 3xZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XwLPHUiUd7u8i6DlgTqpUvjVOFN4vpyWhbccIRdmj5g=; b=fx3YVdlEF5t2wyoMi1Ih0VqrweiTlMuBZRL/luT19mpEcmjghf2pSsT3i8SBWApCqE bJc2yDNcQBRGY4+L+cX6mhry0o6IOpDoWzW9h9M/V2Hpuen923HE4RUZP/Grx/Oc/MGm ZH94OY+5dlDCUZtCzwAsyxJRZbhB1fQAJIo+2eW2GR+5czO/LrAmu0Aq6jp713eF+IeR ApyRMGuMxHCs9068IB3ec075xm8boJcBJ0bjhQac8CPwoFE4XWlk0JMYgSVkjWF+Rf12 mgTRPBV7YBsqYTbQwKS5bUrgbkfhWPjK0wJxqTSUc1roXFrrcN8D2+9u1OEcLBU7Dc5n 7GTw== X-Gm-Message-State: AOAM530pCO02EUg5F9jbCowX/KBYnsd5qT76Ecij/2VEfVvugvtj3tgL bCNJamU8gRmlJE0SzjdJSTebpQ== X-Google-Smtp-Source: ABdhPJz7Z3lbibvn2eFNKQQVtNher7YiK3Ofc/8i1HS+2vEqMXpOmSAwue/dzldCRTy5t7UVFKYj5w== X-Received: by 2002:adf:f842:: with SMTP id d2mr5069407wrq.55.1593190557481; Fri, 26 Jun 2020 09:55:57 -0700 (PDT) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id x5sm18654706wmg.2.2020.06.26.09.55.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 09:55:56 -0700 (PDT) From: Bartosz Golaszewski To: Jonathan Corbet , Greg Kroah-Hartman , "Rafael J . Wysocki" , Guenter Roeck , Jean Delvare Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 4/5] devres: provide devm_krealloc() Date: Fri, 26 Jun 2020 18:55:34 +0200 Message-Id: <20200626165535.7662-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200626165535.7662-1-brgl@bgdev.pl> References: <20200626165535.7662-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Bartosz Golaszewski Implement the managed variant of krealloc(). This function works with all memory allocated by devm_kmalloc() (or devres functions using it implicitly like devm_kmemdup(), devm_kstrdup() etc.). Managed realloc'ed chunks can be manually released with devm_kfree(). Signed-off-by: Bartosz Golaszewski --- .../driver-api/driver-model/devres.rst | 1 + drivers/base/devres.c | 42 +++++++++++++++++++ include/linux/device.h | 2 + 3 files changed, 45 insertions(+) diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst index e0b58c392e4f..0a2572c3813c 100644 --- a/Documentation/driver-api/driver-model/devres.rst +++ b/Documentation/driver-api/driver-model/devres.rst @@ -352,6 +352,7 @@ MEM devm_kfree() devm_kmalloc() devm_kmalloc_array() + devm_krealloc() devm_kmemdup() devm_kstrdup() devm_kvasprintf() diff --git a/drivers/base/devres.c b/drivers/base/devres.c index 1df1fb10b2d9..baf41a290356 100644 --- a/drivers/base/devres.c +++ b/drivers/base/devres.c @@ -834,6 +834,48 @@ void *devm_kmalloc(struct device *dev, size_t size, gfp_t gfp) } EXPORT_SYMBOL_GPL(devm_kmalloc); +void *devm_krealloc(struct device *dev, void *ptr, size_t new_size, gfp_t gfp) +{ + struct devres *old_dr, *new_dr; + struct list_head old_head; + unsigned long flags; + void *ret = NULL; + size_t tot_size; + + if (unlikely(!new_size)) { + devm_kfree(dev, ptr); + return ZERO_SIZE_PTR; + } + + if (unlikely(!ptr)) + return devm_kmalloc(dev, new_size, gfp); + + if (!check_dr_size(new_size, &tot_size)) + return NULL; + + spin_lock_irqsave(&dev->devres_lock, flags); + + old_dr = find_dr(dev, devm_kmalloc_release, devm_kmalloc_match, ptr); + if (WARN_ONCE(!old_dr, "Memory chunk not managed or managed by a different device")) + goto out; + + old_head = old_dr->node.entry; + + new_dr = krealloc(old_dr, tot_size, gfp); + if (!new_dr) + goto out; + + if (new_dr != old_dr) + list_replace(&old_head, &new_dr->node.entry); + + ret = new_dr->data; + +out: + spin_unlock_irqrestore(&dev->devres_lock, flags); + return ret; +} +EXPORT_SYMBOL_GPL(devm_krealloc); + /** * devm_kstrdup - Allocate resource managed space and * copy an existing string into that. diff --git a/include/linux/device.h b/include/linux/device.h index 9cadb647cacc..228063c6392c 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -201,6 +201,8 @@ int devres_release_group(struct device *dev, void *id); /* managed devm_k.alloc/kfree for device drivers */ void *devm_kmalloc(struct device *dev, size_t size, gfp_t gfp) __malloc; +void *devm_krealloc(struct device *dev, void *ptr, size_t size, + gfp_t gfp) __must_check; __printf(3, 0) char *devm_kvasprintf(struct device *dev, gfp_t gfp, const char *fmt, va_list ap) __malloc; __printf(3, 4) char *devm_kasprintf(struct device *dev, gfp_t gfp, From patchwork Fri Jun 26 16:55:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 11628059 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E0C1792A for ; Fri, 26 Jun 2020 16:56:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C5B75207FC for ; Fri, 26 Jun 2020 16:56:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="KoEiu9Od" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728115AbgFZQ4I (ORCPT ); Fri, 26 Jun 2020 12:56:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728112AbgFZQ4A (ORCPT ); Fri, 26 Jun 2020 12:56:00 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5215C03E97A for ; Fri, 26 Jun 2020 09:55:59 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id j4so7704067wrp.10 for ; Fri, 26 Jun 2020 09:55:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sza+GT2lqcd6jmiOYegQQQLgqoPbDI9CeS4XhKI3V1o=; b=KoEiu9OdEBcBWWP+UosBbqAfR1V47vQAzO8kl+t1wgf0SG1vI7+YdJmA7Wys11RMex ZMXx+mBH/viOzmxJj160qrt0OrYr92gNS4xmUzOC0X2/dr2qeiQ9Ece18Tbq0Z5Vk1id nR2RNxEZXUeZerlrtFotgtBYWJ8eEaiSmCMBwCfcc1ATLbcrhsZ8bpf7kr8CyoZUNofo Fi7UswHyjnS7p4q/0aqVUk7v6CvzEAoU6wozvFuFBFvguMxBvB/zm+AhU0+cgp15Uxj/ qtstFFn3hZZFA0q7vM3b0/m5UxZcjGWJk6ec5oB+LU1JDjH1Nszdn/6NnI6Zu21L7NUw P3pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sza+GT2lqcd6jmiOYegQQQLgqoPbDI9CeS4XhKI3V1o=; b=Y3/CtsHXBa/y+ar7DL4rKIjslrWuIVKdrGbk/k0UveIqqoGRsG8krvcGpwsFTmJ1Cm FrHUD4ZxLkjQSpYnJ/SUG3UfNKu5Srn70rFF8nesNcqRyC4VDjupOGTYNh45PXwSjcx/ sQzladT0hj75GWIyzlHAFzxEmdLfwmyxgf7hywZgFlSZQeGa6Rp1+BKKmXFbnVyZEpaT 3FVtCbos9gpDx2WK0tXMkEMUcmo0yv8zEGdWCAEaROoPZVMTBm6sTwlI4/3NRn3jI8Nl SoVd0m3aEpc1k73fpLFq7l+pYw8NegMf+r2sr3QqFrRUQh4ktOfPPP9jbl0FbdpY7wFZ a6Eg== X-Gm-Message-State: AOAM531RinhVmkbJTHkBdfTU8LDsOfEdv7eTTgS03nFsxybUeNTY/Pm6 Ps9Fu7cPAdDEcHR7tkQ6bTH5eA== X-Google-Smtp-Source: ABdhPJzCV6/MN+xqvykEQMSCCNNo3cu4VV3JYPC+A7Y7onUQZRBgd+j3p7NkVTzX64hm46KgPbdFjA== X-Received: by 2002:adf:a49c:: with SMTP id g28mr5051129wrb.118.1593190558547; Fri, 26 Jun 2020 09:55:58 -0700 (PDT) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id x5sm18654706wmg.2.2020.06.26.09.55.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 09:55:58 -0700 (PDT) From: Bartosz Golaszewski To: Jonathan Corbet , Greg Kroah-Hartman , "Rafael J . Wysocki" , Guenter Roeck , Jean Delvare Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 5/5] hwmon: pmbus: use more devres helpers Date: Fri, 26 Jun 2020 18:55:35 +0200 Message-Id: <20200626165535.7662-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200626165535.7662-1-brgl@bgdev.pl> References: <20200626165535.7662-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Bartosz Golaszewski Shrink pmbus code by using devm_hwmon_device_register_with_groups() and devm_krealloc() instead of their non-managed variants. Signed-off-by: Bartosz Golaszewski --- drivers/hwmon/pmbus/pmbus_core.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index a420877ba533..af74504647b8 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -1022,9 +1022,9 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr) { if (data->num_attributes >= data->max_attributes - 1) { int new_max_attrs = data->max_attributes + PMBUS_ATTR_ALLOC_SIZE; - void *new_attrs = krealloc(data->group.attrs, - new_max_attrs * sizeof(void *), - GFP_KERNEL); + void *new_attrs = devm_krealloc(data->dev, data->group.attrs, + new_max_attrs * sizeof(void *), + GFP_KERNEL); if (!new_attrs) return -ENOMEM; data->group.attrs = new_attrs; @@ -2538,7 +2538,7 @@ int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id, ret = pmbus_find_attributes(client, data); if (ret) - goto out_kfree; + return ret; /* * If there are no attributes, something is wrong. @@ -2546,35 +2546,27 @@ int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id, */ if (!data->num_attributes) { dev_err(dev, "No attributes found\n"); - ret = -ENODEV; - goto out_kfree; + return -ENODEV; } data->groups[0] = &data->group; memcpy(data->groups + 1, info->groups, sizeof(void *) * groups_num); - data->hwmon_dev = hwmon_device_register_with_groups(dev, client->name, - data, data->groups); + data->hwmon_dev = devm_hwmon_device_register_with_groups(dev, + client->name, data, data->groups); if (IS_ERR(data->hwmon_dev)) { - ret = PTR_ERR(data->hwmon_dev); dev_err(dev, "Failed to register hwmon device\n"); - goto out_kfree; + return PTR_ERR(data->hwmon_dev); } ret = pmbus_regulator_register(data); if (ret) - goto out_unregister; + return ret; ret = pmbus_init_debugfs(client, data); if (ret) dev_warn(dev, "Failed to register debugfs\n"); return 0; - -out_unregister: - hwmon_device_unregister(data->hwmon_dev); -out_kfree: - kfree(data->group.attrs); - return ret; } EXPORT_SYMBOL_GPL(pmbus_do_probe); @@ -2585,7 +2577,6 @@ int pmbus_do_remove(struct i2c_client *client) debugfs_remove_recursive(data->debugfs); hwmon_device_unregister(data->hwmon_dev); - kfree(data->group.attrs); return 0; } EXPORT_SYMBOL_GPL(pmbus_do_remove);