From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1718C32771 for ; Sat, 24 Sep 2022 03:10:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232018AbiIXDKa (ORCPT ); Fri, 23 Sep 2022 23:10:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230495AbiIXDK2 (ORCPT ); Fri, 23 Sep 2022 23:10:28 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB5783B71D for ; Fri, 23 Sep 2022 20:10:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1663989027; x=1695525027; h=date:message-id:from:to:cc:subject:in-reply-to: references:mime-version; bh=chsh7xys3hBCqEKdp+1zP6wS9ZuMZBpTgni+79xMQWI=; b=oAGsnM9miEOwOiAlvbTM0PtEkkOSLTA4r4Euu4wsRq9+HmyhvRaTVUGv dGc9KiH8RJp1Cdni+V3Yb1Ze1vJmijQkIVxpAO1+6gGPOp493ppR+TC9Z 38BzsJMMuLnMjJUjFRouPdLU/f9AO8eq4PkAwm50xPKsJnU2WXlF34bvA n5s5IX9cfLtdvrgJHmt6Xev7A0IbtBUM23z2kgn2pEvpF4WMAZtlg5Y4B d3mK1xNHvBL/5JzLmbIjK3vKhLUK5ePNiO7qGIUzqfVoXUJBizLhJjEKZ lr0LQR0td5k/s2WHDDoJuAR6bRB8sW373RmuWEJF1x7vd2Wd0Lc2UrySe Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10479"; a="287863747" X-IronPort-AV: E=Sophos;i="5.93,340,1654585200"; d="scan'208";a="287863747" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Sep 2022 20:10:27 -0700 X-IronPort-AV: E=Sophos;i="5.93,340,1654585200"; d="scan'208";a="598098356" Received: from adixit-mobl.amr.corp.intel.com (HELO adixit-arch.intel.com) ([10.252.138.221]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Sep 2022 20:10:27 -0700 Date: Fri, 23 Sep 2022 20:10:26 -0700 Message-ID: <87sfkh8o2l.wl-ashutosh.dixit@intel.com> From: "Dixit, Ashutosh" To: Andi Shyti Cc: Badal Nilawar , linux-hwmon@vger.kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: Re: [Intel-gfx] [PATCH 1/7] drm/i915/hwmon: Add HWMON infrastructure In-Reply-To: References: <20220916150054.807590-1-badal.nilawar@intel.com> <20220916150054.807590-2-badal.nilawar@intel.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?ISO-8859-4?Q?Goj=F2?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/28.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org On Wed, 21 Sep 2022 05:44:35 -0700, Andi Shyti wrote: > > > +void i915_hwmon_register(struct drm_i915_private *i915) > > +{ > > + struct device *dev = i915->drm.dev; > > + struct i915_hwmon *hwmon; > > + struct device *hwmon_dev; > > + struct hwm_drvdata *ddat; > > + > > + /* hwmon is available only for dGfx */ > > + if (!IS_DGFX(i915)) > > + return; > > + > > + hwmon = kzalloc(sizeof(*hwmon), GFP_KERNEL); > > why don't we use devm_kzalloc? > > > + if (!hwmon) > > + return; > > + > > + i915->hwmon = hwmon; > > + mutex_init(&hwmon->hwmon_lock); > > + ddat = &hwmon->ddat; > > + > > + ddat->hwmon = hwmon; > > + ddat->uncore = &i915->uncore; > > + snprintf(ddat->name, sizeof(ddat->name), "i915"); > > + > > + hwm_get_preregistration_info(i915); > > + > > + /* hwmon_dev points to device hwmon */ > > + hwmon_dev = hwmon_device_register_with_info(dev, ddat->name, > > + ddat, > > + &hwm_chip_info, > > + NULL); > > + if (IS_ERR(hwmon_dev)) { > > + mutex_destroy(&hwmon->hwmon_lock); > > there is not such a big need to destroy the mutex. Destroying > mutexes is more useful when you actually are creating/destroying > and there is some debug need. I don't think that's the case. > > With the devm_kzalloc this would be just a return. If we are using devm_kzalloc we might as well replace all the hwmon_device_register_with_info's (in Patch 1 and 7) with devm_hwmon_device_register_with_info and then i915_hwmon_unregister is just this: void i915_hwmon_unregister(struct drm_i915_private *i915) { fetch_and_zero(&i915->hwmon); } Even the above statement is probably not needed but might as well retain it for sanity. So this is a simple change. Thanks. -- Ashutosh