From nobody Thu Sep 19 23:23:50 2024 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D40E1CF2B4 for ; Wed, 4 Sep 2024 09:00:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725440440; cv=none; b=KXuERhVVFw0Y94RSySNOLXK20OPHu5QpDS2XOg1lWgDEELSuerZTN6ylHNd1QxMS6giKUXeNuv8wdlkOeU9+2ekqfAoxAN60J2NaGvsekYtUfMZIG808SmixF/gqFQNs8ydo2VYtkgnaPdHVAyx7wt5JdMUWHVy4xSiXFN5li08= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725440440; c=relaxed/simple; bh=vfouHZ0OIsqMydCSjbbh9j+9aQPzT5coh1Y7d+J5JLY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nf/v1NTnY3lASm2+DSqPdY9NGtO91KIngJLAdL196hyPtUb7ql+K5E+wGWXNK8zhOPdF6PIev7gsHIDMBgadLCM5Hn+xNDqpYnFEStglQhFyHU8S9AJ6vtOciIVWKQPVrPfC94Z1E70gFKvXcPCw0YR5gC+MaGz4WHndEujd5Io= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=TsTjsS65; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="TsTjsS65" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-715abede256so4818906b3a.3 for ; Wed, 04 Sep 2024 02:00:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725440438; x=1726045238; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=b0sbG/jw58dFVSs3/2Q1ZWzAnnopRuiveILCTgaftSY=; b=TsTjsS65B3VlAtj0fcmcNx4Y2WPTTocs8Bqn/+3UoIRruTcibCyzitSpCl2Frqu6pf cLvd+if/yl6ajW79KuWUtOMhsxQ8H9DPG5aYRTi9B+tfhRpPdY8vE9KGM5cCjBr0qRie 05vuCqU63YRbK5KS1mQosOmsmWlW23dOVM2ak= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725440438; x=1726045238; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=b0sbG/jw58dFVSs3/2Q1ZWzAnnopRuiveILCTgaftSY=; b=uAQtS6GbmiV6ormKoRrvemD0PJllk0pR4VhunlAxojS13O2OUiccDOQucZOhcwtvZB 7puEejD6dPfWMXcL0RZ40MoCmj6lmddNse45W+eKnly4vzbdOwMsNpSvUt/p1Hqe4+I3 QdviSLTFDl7+PEz0DYx9cCtAqX6H9JC2DQJL4kp5/O4oZfR8nEHQw26ui81kNjN3Edko 8/4SiNauly1zPmklQrPNmmXzCCovjNmSTt9aUVXI9R0cknhugtHVcv0M17i4nTdyXJUM SOwJSWS8k4KIUjtHV2iFg/EptUH42JDTtbCdaJbyNszB6pUfduYcP2gO/s+/oG6wOz5u 1LZA== X-Forwarded-Encrypted: i=1; AJvYcCVSHGkPzbAf3VRZn4eSlq2TxbQ1GXp1tTTrakMc3VMUzRtZIQHVCQtZurTjhnfaqp9HVg4NHgbigSk0MAI=@vger.kernel.org X-Gm-Message-State: AOJu0Yy5/EhxEssFsOO+VJ5so6cc869U/YS98S8DNLijLUSTa8qA3YTh zdb6j6zKVWfEosvQUFSqw7d7/OYrfp9JYEYgzNUT+NlvEONnnkD4mI53NGeZsA== X-Google-Smtp-Source: AGHT+IFJnhX8EeVHE/Pb/2Pe1cdA+zN3kwfbn5THcKUWQl9Uebvww0bAh3IhVagxcNqMcqnK8VZyqg== X-Received: by 2002:a05:6a21:6e4b:b0:1c6:ac08:8dd2 with SMTP id adf61e73a8af0-1ced6087aaemr11569081637.15.1725440437588; Wed, 04 Sep 2024 02:00:37 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:83fc:5c8e:13bd:d165]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-717785b5183sm1153279b3a.197.2024.09.04.02.00.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 02:00:37 -0700 (PDT) From: Chen-Yu Tsai To: Rob Herring , Saravana Kannan , Matthias Brugger , AngeloGioacchino Del Regno , Wolfram Sang , Benson Leung , Tzung-Bi Shih , Mark Brown , Liam Girdwood Cc: Chen-Yu Tsai , chrome-platform@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Douglas Anderson , Johan Hovold , Jiri Kosina , Andy Shevchenko , linux-i2c@vger.kernel.org Subject: [PATCH v6 04/12] regulator: Split up _regulator_get() Date: Wed, 4 Sep 2024 17:00:06 +0800 Message-ID: <20240904090016.2841572-5-wenst@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240904090016.2841572-1-wenst@chromium.org> References: <20240904090016.2841572-1-wenst@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" _regulator_get() contains a lot of common code doing checks prior to the regulator lookup and housekeeping work after the lookup. Almost all the code could be shared with a OF-specific variant of _regulator_get(). Split out the common parts so that they can be reused. The OF-specific version of _regulator_get() will be added in a subsequent patch. No functional changes were made. Signed-off-by: Chen-Yu Tsai --- Changes since v5: - Fixed kerneldoc "Return" section format for _regulator_get_common() - Slightly reworded return value description Changes since v4: - New patch --- drivers/regulator/core.c | 54 ++++++++++++++++++++++++++++-------- drivers/regulator/internal.h | 4 +++ 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 835a5531d045..d60c86477ac2 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2103,26 +2103,43 @@ static int regulator_resolve_supply(struct regulato= r_dev *rdev) return ret; } =20 -/* Internal regulator request function */ -struct regulator *_regulator_get(struct device *dev, const char *id, - enum regulator_get_type get_type) +/* common pre-checks for regulator requests */ +int _regulator_get_common_check(struct device *dev, const char *id, + enum regulator_get_type get_type) { - struct regulator_dev *rdev; - struct regulator *regulator; - struct device_link *link; - int ret; - if (get_type >=3D MAX_GET_TYPE) { dev_err(dev, "invalid type %d in %s\n", get_type, __func__); - return ERR_PTR(-EINVAL); + return -EINVAL; } =20 if (id =3D=3D NULL) { dev_err(dev, "regulator request with no identifier\n"); - return ERR_PTR(-EINVAL); + return -EINVAL; } =20 - rdev =3D regulator_dev_lookup(dev, id); + return 0; +} + +/** + * _regulator_get_common - Common code for regulator requests + * @rdev: regulator device pointer as returned by *regulator_dev_lookup() + * Its reference count is expected to have been incremented. + * @dev: device used for dev_printk messages + * @id: Supply name or regulator ID + * @get_type: enum regulator_get_type value corresponding to type of reque= st + * + * Returns: pointer to struct regulator corresponding to @rdev, or ERR_PTR= () + * encoded error. + * + * This function should be chained with *regulator_dev_lookup() functions. + */ +struct regulator *_regulator_get_common(struct regulator_dev *rdev, struct= device *dev, + const char *id, enum regulator_get_type get_type) +{ + struct regulator *regulator; + struct device_link *link; + int ret; + if (IS_ERR(rdev)) { ret =3D PTR_ERR(rdev); =20 @@ -2238,6 +2255,21 @@ struct regulator *_regulator_get(struct device *dev,= const char *id, return regulator; } =20 +/* Internal regulator request function */ +struct regulator *_regulator_get(struct device *dev, const char *id, + enum regulator_get_type get_type) +{ + struct regulator_dev *rdev; + int ret; + + ret =3D _regulator_get_common_check(dev, id, get_type); + if (ret) + return ERR_PTR(ret); + + rdev =3D regulator_dev_lookup(dev, id); + return _regulator_get_common(rdev, dev, id, get_type); +} + /** * regulator_get - lookup and obtain a reference to a regulator. * @dev: device for regulator "consumer" diff --git a/drivers/regulator/internal.h b/drivers/regulator/internal.h index 8e5506c5ee94..5b43f802468d 100644 --- a/drivers/regulator/internal.h +++ b/drivers/regulator/internal.h @@ -121,6 +121,10 @@ enum regulator_get_type { MAX_GET_TYPE }; =20 +int _regulator_get_common_check(struct device *dev, const char *id, + enum regulator_get_type get_type); +struct regulator *_regulator_get_common(struct regulator_dev *rdev, struct= device *dev, + const char *id, enum regulator_get_type get_type); struct regulator *_regulator_get(struct device *dev, const char *id, enum regulator_get_type get_type); int _regulator_bulk_get(struct device *dev, int num_consumers, --=20 2.46.0.469.g59c65b2a67-goog