Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4544043imm; Wed, 30 May 2018 07:33:32 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKkCYnjJwMCvrKZYraWlsB0BRh3Z+QJJWPpaidlaSDKLtTA4HSo0ZPTCvCaLpxMI2PCAgr2 X-Received: by 2002:a63:7b1e:: with SMTP id w30-v6mr2435132pgc.249.1527690812323; Wed, 30 May 2018 07:33:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527690812; cv=none; d=google.com; s=arc-20160816; b=bwtiE9SqQ8INd9Utg/9Xt42cUMLPKzgO8h2D6jih41c+Z4H0mi2ZesXKoDicWE4NUi UjJTkYE9LOwjdmblWSGJap0Fjsn9SARYFeei+nYJsybTepfT5NHJgVsflPuXzqXPRBmc Nj/zhZcoAkeNQsbELS8c3dtsVE4HO6eKnypdSXHVKrAwXov1In/gPdpanHHSaIjw3rf/ wJA24Uh7qnj9beu40Lmv/eTGtHaScUFMzqMwnBEiQmgnPCSVoLHfswXLn7iooJ6dA6cA uJiQYuq7FnKhSiEXkbJAFOuAQGxf3SYDMBnyquC0bTxbHEyVEY5AlllyJUfmPq03I9Ag ZFvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=jMBVL37cVg6N+07RczrDPu8M9olbNirk5gBQrSxexeM=; b=jGPQVkUVLfNNIdpO6Hj4kZn0L65ClLlvLxo56g7+0YBPyOsYo4WBhoFd7v0wND4pui FdkXOdy/TbJJJ7xpxLHk1aj8ury1378C2LhHXOp1IQWYb6WGSJYdMlIzosOA2NaQRIbK yoGXzjjQY9PSnA+cX/SIz15IHa8itxKH5kLqi37q+7YyN6fW1t8cFxGd5PtQUGaPR1l1 cSM3/4k1Sr/YawzW6svyK2jjhwSWkl90dN+dpJ6vTiOmEekAw4N5SN4MWrZtg84Zxmrv AFGgilfczdND37b58JSy/E8dgSVSHrv61Hz47CNTR/7NxKC2dCve+qd1ZDPs/nOu8zVM 9f+A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h7-v6si27619381pgc.14.2018.05.30.07.33.17; Wed, 30 May 2018 07:33:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753142AbeE3OcY (ORCPT + 99 others); Wed, 30 May 2018 10:32:24 -0400 Received: from mail.bootlin.com ([62.4.15.54]:44856 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751369AbeE3OcW (ORCPT ); Wed, 30 May 2018 10:32:22 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id C3B9B20828; Wed, 30 May 2018 16:32:20 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (AAubervilliers-681-1-125-111.w90-88.abo.wanadoo.fr [90.88.63.111]) by mail.bootlin.com (Postfix) with ESMTPSA id 5B12B20713; Wed, 30 May 2018 16:32:20 +0200 (CEST) Date: Wed, 30 May 2018 16:32:20 +0200 From: Boris Brezillon To: Frieder Schrempf Cc: linux-mtd@lists.infradead.org, linux-spi@vger.kernel.org, dwmw2@infradead.org, computersforpeace@gmail.com, marek.vasut@gmail.com, richard@nod.at, miquel.raynal@bootlin.com, broonie@kernel.org, david.wolfe@nxp.com, fabio.estevam@nxp.com, prabhakar.kushwaha@nxp.com, yogeshnarayan.gaur@nxp.com, han.xu@nxp.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH 01/11] spi: spi-mem: Extend the SPI mem interface to set a custom memory name Message-ID: <20180530163220.161fdb86@bbrezillon> In-Reply-To: <1527686082-15142-2-git-send-email-frieder.schrempf@exceet.de> References: <1527686082-15142-1-git-send-email-frieder.schrempf@exceet.de> <1527686082-15142-2-git-send-email-frieder.schrempf@exceet.de> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Frieder, On Wed, 30 May 2018 15:14:30 +0200 Frieder Schrempf wrote: > When porting (Q)SPI controller drivers from the MTD layer to the SPI > layer, the naming scheme for the memory devices changes. To be able > to keep compatibility with the old drivers naming scheme, a function > is added to the SPI mem interface to let controller drivers set a > custom name for the memory. > > Example for the FSL QSPI driver: > > Name with the old driver: 21e0000.qspi, > or with multiple devices: 21e0000.qspi-0, 21e0000.qspi-1, ... > > Name with the new driver without spi_mem_get_name: spi4.0 > > Signed-off-by: Frieder Schrempf > --- > drivers/spi/spi-mem.c | 25 +++++++++++++++++++++++++ > include/linux/spi/spi-mem.h | 3 +++ > 2 files changed, 28 insertions(+) > > diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c > index 990770d..5e9af47 100644 > --- a/drivers/spi/spi-mem.c > +++ b/drivers/spi/spi-mem.c > @@ -311,6 +311,31 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op) > EXPORT_SYMBOL_GPL(spi_mem_exec_op); > > /** > + * spi_mem_get_name() - Let drivers using the SPI mem interface specify a > + * custom name for the memory to avoid compatibility > + * issues with ported drivers. > + * @mem: the SPI memory > + * > + * When porting (Q)SPI controller drivers from the MTD layer to the SPI > + * layer, the naming scheme for the memory devices changes. To be able to > + * keep compatibility with the old drivers naming scheme, this function can > + * be used to get a custom name from the controller driver. > + * If no custom name is available, the name of the SPI device is returned. > + * > + * Return: a char array that contains the name for the flash memory > + */ > +const char *spi_mem_get_name(struct spi_mem *mem) > +{ > + struct spi_controller *ctlr = mem->spi->controller; > + > + if (ctlr->mem_ops && ctlr->mem_ops->get_name) > + return ctlr->mem_ops->get_name(mem); Looks like your implementation of ->get_name() in the fsl driver is allocating a new string each time it's called. I guess other implementations might be forced to do the same, so maybe it's better to add a ->name field to struct spi_mem and only call ->get_name() once when the device is probed. Then spi_mem_get_name() can just be implemented like this: const char *spi_mem_get_name(struct spi_mem *mem) { return mem->name; } Regards, Boris > + > + return dev_name(&mem->spi->dev); > +} > +EXPORT_SYMBOL_GPL(spi_mem_get_name); > + > +/** > * spi_mem_adjust_op_size() - Adjust the data size of a SPI mem operation to > * match controller limitations > * @mem: the SPI memory > diff --git a/include/linux/spi/spi-mem.h b/include/linux/spi/spi-mem.h > index 4fa34a2..f1912d3 100644 > --- a/include/linux/spi/spi-mem.h > +++ b/include/linux/spi/spi-mem.h > @@ -178,6 +178,7 @@ struct spi_controller_mem_ops { > const struct spi_mem_op *op); > int (*exec_op)(struct spi_mem *mem, > const struct spi_mem_op *op); > + const char *(*get_name)(struct spi_mem *mem); > }; > > /** > @@ -236,6 +237,8 @@ bool spi_mem_supports_op(struct spi_mem *mem, > int spi_mem_exec_op(struct spi_mem *mem, > const struct spi_mem_op *op); > > +const char *spi_mem_get_name(struct spi_mem *mem); > + > int spi_mem_driver_register_with_owner(struct spi_mem_driver *drv, > struct module *owner); >