Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4622293pxb; Sun, 14 Feb 2021 17:54:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJwcB4FuJvI2BJOg+NHvqmxoYsHkpTyyNW9lH8H7XIxevkaqSkNbTN6Jl/JFFsnEfxrscINP X-Received: by 2002:a05:6402:1014:: with SMTP id c20mr13952862edu.53.1613354072569; Sun, 14 Feb 2021 17:54:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613354072; cv=none; d=google.com; s=arc-20160816; b=h37r/ENM6HOHepZJ9MMtqP+c08w8R2g2lu1rDwzy/d3qDhdRiUAVEXRNjGYDQdr97V PkbmVaRfuAU938OhdS4gaTJCOIrt40ERf+sfYWjc1Bts5PpvCh7mFOeRrQsVElhCwgHb nv+lKaa1voG0WMsaaaScVi3EjblRoO6+tcO2mnqdmtw7SIziqmRWn5660eB3MTr0YD9+ dDU/dTqTl4uHSwmnjWZzPhq3YrkvPggQvZaN26L0ujm51ogY4PhS3LWKhY6UTGSEwj4u 6vIepqg3GfZyXzJF4bveLTuwD9b0N/ffrBbt6WF01JbhoLRzCPDPgr3NimOo919czCEs fGzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=66Gpo3THQwpAPEL1nYuvGvP8jeKMfFXdb8gVgziwIg4=; b=s+BqJDTEGF4JjNE0YoHI4biZ069L0+UoRK5udsgTvoZk6V6XogF8dqMw+Jj/GOkw/Y tn7daXmu9iDF6DfrWpr4mLIFaph9rR6miM2MEXmsJ4xMOBxDuhk8dZyOagkvByae6RDJ cpnYe7ruBzCGtSj34FFBMBs6o4Tk7myvfHpG3whPTmFfhk0HvYj/Zb5jK0YWcELeFXJP bJ+1SDomEPsjtjFMst00nTD6Np6XNvl6IcgP0uRzXyvCDYdkIJ71KXHr2yfPCJn6Rb49 j9b4+8CGj/JTantTo5Gclc3mg7J1ZeozB/mBDl4M1gPGVY6udwN2n1aSveALkdrFwLFX sOew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=YlH4KGRz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l20si1555408ejr.224.2021.02.14.17.53.53; Sun, 14 Feb 2021 17:54:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=YlH4KGRz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229729AbhBOBwM (ORCPT + 99 others); Sun, 14 Feb 2021 20:52:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229609AbhBOBwL (ORCPT ); Sun, 14 Feb 2021 20:52:11 -0500 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8C21C061574; Sun, 14 Feb 2021 17:51:31 -0800 (PST) Received: by mail-pf1-x42c.google.com with SMTP id m6so3282549pfk.1; Sun, 14 Feb 2021 17:51:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=66Gpo3THQwpAPEL1nYuvGvP8jeKMfFXdb8gVgziwIg4=; b=YlH4KGRz7vhGHvJoW2mJvpOice9AgV+D6hVGVcPsCeSEWPhfwTf4CbXxvAP79zio3M YespDkqvTSRKDClI9wwQksEUuC/mBmFV5DHJicsKbHVpwhLqNm3HuCkUvxS2+6jl2kDE kjhQbsVidZjHav/8HzWOiS6GNwUXDY3cED+J/J6gjCVKt39d+XC1rHeILxLwCWh2Kl5Z WvRzyrYqdGkdSDh/Nidhfp/QxavY5TtXeW02VtrTkMkzY/Cy1Db44WclSSSQbb402VGz P2rjen49SQSC/zDaoPZlRTv8p7qExtrA6ujUe7qlqVSGL2809IWHUFZPAg6XNzqWSSXc 1o2Q== 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:mime-version :content-transfer-encoding; bh=66Gpo3THQwpAPEL1nYuvGvP8jeKMfFXdb8gVgziwIg4=; b=k2kzvzVSnu6TDtY9awQ8F9EGZjPFXUC/fkiTVMQy+uLLJdXSMG6dXheQ2WlLOG4Oji 2I+iL33dxxUQ3CQJnC2aOF8y8+ex5TnMRk8UgN4Lt2ehos1JXPZyhnjI6xPVRWwWTuEd GMOkArKPBN8cPi4bl0FFntbBgVaW/UXXmDlJA0XH3rdkGUYcL/qcR/Zh6h8KHO3174aT 4yEozzdVkl1JLknBiaBuOlLSIW0Ad7FhjZON3ERX8TDgavJ18gbF5MbvleWHOTZI3F+/ 4J583MV3EI3+d0yzM84pHuZW3QbfhZvmUR9DjU7t39cbI1qw+QPLNPWJxSepZZuayAHi hliw== X-Gm-Message-State: AOAM533aR8L5JzgbtZag/QOkUDHw1Nc3EweEi8kJ5/1ejoIVPkMWt1cp Lo01RO05TxYBljX09UnXhF2RXHKGJRy9DtbO X-Received: by 2002:a62:8445:0:b029:1c1:c862:8fc4 with SMTP id k66-20020a6284450000b02901c1c8628fc4mr13112877pfd.77.1613353891040; Sun, 14 Feb 2021 17:51:31 -0800 (PST) Received: from tj.ccdomain.com ([103.220.76.197]) by smtp.gmail.com with ESMTPSA id j3sm14993653pjs.50.2021.02.14.17.51.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Feb 2021 17:51:30 -0800 (PST) From: Yue Hu To: ulf.hansson@linaro.org Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, huyue2@yulong.com, zhangwen@yulong.com, zbestahu@163.com Subject: [PATCH] mmc: core: Reduce code duplication to mmc_spi_send_{csd|cid} Date: Mon, 15 Feb 2021 09:51:16 +0800 Message-Id: <20210215015116.1355-1-zbestahu@gmail.com> X-Mailer: git-send-email 2.29.2.windows.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yue Hu mmc_spi_send_{csd|cid} have similar function body. Let's remove the duplicated part to simplify the code, just add opcode to distinguish them in changed mmc_spi_send_cxd(). Signed-off-by: Yue Hu --- drivers/mmc/core/mmc_ops.c | 39 +++++++++------------------------------ 1 file changed, 9 insertions(+), 30 deletions(-) diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index 265d95e..f413474 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -296,61 +296,40 @@ int mmc_set_relative_addr(struct mmc_card *card) return 0; } -static int mmc_spi_send_csd(struct mmc_host *host, u32 *csd) +static int mmc_spi_send_cxd(struct mmc_host *host, u32 *cxd, u32 opcode) { int ret, i; - __be32 *csd_tmp; + __be32 *cxd_tmp; - csd_tmp = kzalloc(16, GFP_KERNEL); - if (!csd_tmp) + cxd_tmp = kzalloc(16, GFP_KERNEL); + if (!cxd_tmp) return -ENOMEM; - ret = mmc_send_cxd_data(NULL, host, MMC_SEND_CSD, csd_tmp, 16); + ret = mmc_send_cxd_data(NULL, host, opcode, cxd_tmp, 16); if (ret) goto err; for (i = 0; i < 4; i++) - csd[i] = be32_to_cpu(csd_tmp[i]); + cxd[i] = be32_to_cpu(cxd_tmp[i]); err: - kfree(csd_tmp); + kfree(cxd_tmp); return ret; } int mmc_send_csd(struct mmc_card *card, u32 *csd) { if (mmc_host_is_spi(card->host)) - return mmc_spi_send_csd(card->host, csd); + return mmc_spi_send_cxd(card->host, csd, MMC_SEND_CSD); return mmc_send_cxd_native(card->host, card->rca << 16, csd, MMC_SEND_CSD); } -static int mmc_spi_send_cid(struct mmc_host *host, u32 *cid) -{ - int ret, i; - __be32 *cid_tmp; - - cid_tmp = kzalloc(16, GFP_KERNEL); - if (!cid_tmp) - return -ENOMEM; - - ret = mmc_send_cxd_data(NULL, host, MMC_SEND_CID, cid_tmp, 16); - if (ret) - goto err; - - for (i = 0; i < 4; i++) - cid[i] = be32_to_cpu(cid_tmp[i]); - -err: - kfree(cid_tmp); - return ret; -} - int mmc_send_cid(struct mmc_host *host, u32 *cid) { if (mmc_host_is_spi(host)) - return mmc_spi_send_cid(host, cid); + return mmc_spi_send_cxd(host, cid, MMC_SEND_CID); return mmc_send_cxd_native(host, 0, cid, MMC_ALL_SEND_CID); } -- 1.9.1