Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp305385ybl; Fri, 9 Aug 2019 06:20:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqyg6obtjy9M0FOVqs55sqEQVlOqAj3EfD6UxBmeTWCXE4R/bgiq/xbxZOuM0QTig6Xse1/z X-Received: by 2002:a62:be0c:: with SMTP id l12mr21578011pff.224.1565356824528; Fri, 09 Aug 2019 06:20:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565356824; cv=none; d=google.com; s=arc-20160816; b=smsMsjIOE1bEWylL4VY8cVPyYHG58RLoPQLg4OgYSWtnoGxktwsXoJwlZgGjiMY9Q0 z5bm5EA1vwtbF5aYtP1I6dBvz1mk7FRX9nNaY/CkiADW121OJOZYT6LwlK4+9oDFjokZ o8hBdPJ8utIqPHLi9NOT6TSVBlcOkfAholEcgcns9t1xi3DLLhVDCfukpdbtANdzRQZn RotVxuiS9pBYADrProcoiNIZvcNBJYcG36yvLfZKW0xHEOTgN/+2jt7g+ipPJLOWyzYE ULW9YBGL5GtO0CQgZT9zwD6B8ShpHo/BG6tv4aUvI6MejOR+iEF1pXKRBrllpI5TgzP5 Ayrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=42uV7DurzBGNdoHGvTqQVRhcHK8QAjR3iIUcZK+4LkY=; b=G8zObgGuflXWo+f6VVPN5wHxMUFZV8bLUEw1ylmwld7G93Vml4LfAcq52E6j7TZnoi Z57MjtgAGPs1vqH+MwvEBIG4vab30bOKxz5b5FpbYDgYFffRxPy2AselETFb9XROxy00 c8CIKtMHC3lpWSHE16MV4jHllgbo/+JCMGchF00Kkr3Jb+4eQD5i0uK0v24E4stW5Ayp CnzJMfJd55ZbhEs658gs0sSB70Gsca8erRreEMcOZgmUPwxEhXetno9mnGeFj6P2jw4v EtDI/DvQAv5GhOsHMfZuLiIgW+S1x96vZOL3cpwA+gkpAvFeg2DKdrbZRDL07dX02LzL /qzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@devtank-co-uk.20150623.gappssmtp.com header.s=20150623 header.b=zIW8ddVR; 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 h27si48521057pgh.388.2019.08.09.06.20.07; Fri, 09 Aug 2019 06:20:24 -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; dkim=pass header.i=@devtank-co-uk.20150623.gappssmtp.com header.s=20150623 header.b=zIW8ddVR; 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 S2436481AbfHINSa (ORCPT + 99 others); Fri, 9 Aug 2019 09:18:30 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:37289 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436470AbfHINS3 (ORCPT ); Fri, 9 Aug 2019 09:18:29 -0400 Received: by mail-wr1-f66.google.com with SMTP id b3so5836591wro.4 for ; Fri, 09 Aug 2019 06:18:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=devtank-co-uk.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=42uV7DurzBGNdoHGvTqQVRhcHK8QAjR3iIUcZK+4LkY=; b=zIW8ddVR27zXLKH9fZhIInf53B0Gh7iwnxOugtzCHM95gAdCzwDF13gpIHDMDlAxDG uCr8usHYX04M3ywP/J0JIo2qJxb9F/86DE1NRBV691y34xB+FdwlA+IrFHEL33I9RDVZ wTJZEiWixNjcgubZnEc0DNqZ+snRpjCjwyYqe4UOANHawkW346V+GKb7jrxlsAlCsU4W EyLEuQx2TYEpRlQX8b80QwT7Ox7h6z9jfom/tnVcpEf9b7zMszSNpD3qS57KfObMI5BK KJl330eUZ3OG9pRM5vCZk/r57nWk4hynC8W0vXJjQT5oH+HkpPhfLv6nKNjJocSjLfOl vXPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=42uV7DurzBGNdoHGvTqQVRhcHK8QAjR3iIUcZK+4LkY=; b=cHOS2xjViJ5sjiwBvgQN4QidXD+8DC2hEq5Rjvc1YL/g6imIVk9Ak3moyOv3VpMR7C uYLxjKn8Nho83WN4RA83tQNr88UZVPIJp/PtMx+7mf7rmEKWjUmqQMbo746HcW1xe3Ip IrTZcb/i7JgCIJfMzXB8wNXHcvzSZCJDkkAQsSKQcBV183bUX8F/csq9Wdaz4i1z1PVU RfNGGJ5s6t7WuvDdpfp9OAmuPSnfhFwreLoygf5ji8pSJmjPw2q2XiwEnEDQwgYAFF0Y TYVKhCFemSzICQREOrAsqOrBLQCYfRN5JXyJP8mS48F2doTpCnPWS0H42TYQJ8jW9Vsm ggsg== X-Gm-Message-State: APjAAAUCJgGX9Pb2Fkf/7D4UZjs50UTt0t6zfsaUCDLICIZGvzJRNieU 3YG+9lRyEGko3+5wOM+vkgq/7chReWA= X-Received: by 2002:adf:eb51:: with SMTP id u17mr23274490wrn.257.1565356706219; Fri, 09 Aug 2019 06:18:26 -0700 (PDT) Received: from [192.168.200.229] ([141.105.200.141]) by smtp.gmail.com with ESMTPSA id d17sm6187647wrm.52.2019.08.09.06.18.25 (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Fri, 09 Aug 2019 06:18:25 -0700 (PDT) Subject: Re: [PATCH] Add optional chip erase functionality to AT25 EEPROM driver. To: Greg Kroah-Hartman Cc: Rob Herring , Mark Rutland , Arnd Bergmann , Srinivas Kandagatla , YueHaibing , Bartosz Golaszewski , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org References: <20190809125358.24440-1-joe.burmeister@devtank.co.uk> <20190809130005.GA13962@kroah.com> From: Joe Burmeister Message-ID: Date: Fri, 9 Aug 2019 14:18:24 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190809130005.GA13962@kroah.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-GB Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Greg, On 09/08/2019 14:00, Greg Kroah-Hartman wrote: > On Fri, Aug 09, 2019 at 01:53:55PM +0100, Joe Burmeister wrote: >> +static void _eeprom_at25_store_erase_locked(struct at25_data *at25) >> +{ >> + unsigned long timeout, retries; >> + int sr, status; >> + u8 cp; >> + >> + cp = AT25_WREN; >> + status = spi_write(at25->spi, &cp, 1); >> + if (status < 0) { >> + dev_dbg(&at25->spi->dev, "ERASE WREN --> %d\n", status); >> + return; >> + } >> + cp = at25->erase_instr; >> + status = spi_write(at25->spi, &cp, 1); >> + if (status < 0) { >> + dev_dbg(&at25->spi->dev, "CHIP_ERASE --> %d\n", status); >> + return; >> + } >> + /* Wait for non-busy status */ >> + timeout = jiffies + msecs_to_jiffies(ERASE_TIMEOUT); >> + retries = 0; >> + do { >> + sr = spi_w8r8(at25->spi, AT25_RDSR); >> + if (sr < 0 || (sr & AT25_SR_nRDY)) { >> + dev_dbg(&at25->spi->dev, >> + "rdsr --> %d (%02x)\n", sr, sr); >> + /* at HZ=100, this is sloooow */ >> + msleep(1); >> + continue; >> + } >> + if (!(sr & AT25_SR_nRDY)) >> + return; >> + } while (retries++ < 200 || time_before_eq(jiffies, timeout)); >> + >> + if ((sr < 0) || (sr & AT25_SR_nRDY)) { >> + dev_err(&at25->spi->dev, >> + "chip erase, timeout after %u msecs\n", >> + jiffies_to_msecs(jiffies - >> + (timeout - ERASE_TIMEOUT))); >> + status = -ETIMEDOUT; >> + return; >> + } >> +} >> + >> + > No need for 2 lines :( Sorry, other coding conventions I'm used to. >> +static ssize_t eeprom_at25_store_erase(struct device *dev, >> + struct device_attribute *attr, >> + const char *buf, size_t count) >> +{ >> + struct at25_data *at25 = dev_get_drvdata(dev); >> + int erase = 0; >> + >> + sscanf(buf, "%d", &erase); >> + if (erase) { >> + mutex_lock(&at25->lock); >> + _eeprom_at25_store_erase_locked(at25); >> + mutex_unlock(&at25->lock); >> + } >> + >> + return count; >> +} >> + >> +static DEVICE_ATTR(erase, S_IWUSR, NULL, eeprom_at25_store_erase); >> + >> + > Same here. > > Also, where is the Documentation/ABI/ update for the new sysfs file? There isn't anything for the existing SPI EEPROM stuff I can see. Would I have to document what was already there to add my bit? >> static int at25_probe(struct spi_device *spi) >> { >> struct at25_data *at25 = NULL; >> @@ -311,6 +379,7 @@ static int at25_probe(struct spi_device *spi) >> int err; >> int sr; >> int addrlen; >> + int has_erase; >> >> /* Chip description */ >> if (!spi->dev.platform_data) { >> @@ -352,6 +421,9 @@ static int at25_probe(struct spi_device *spi) >> spi_set_drvdata(spi, at25); >> at25->addrlen = addrlen; >> >> + /* Optional chip erase instruction */ >> + device_property_read_u8(&spi->dev, "chip_erase_instruction", &at25->erase_instr); >> + >> at25->nvmem_config.name = dev_name(&spi->dev); >> at25->nvmem_config.dev = &spi->dev; >> at25->nvmem_config.read_only = chip.flags & EE_READONLY; >> @@ -370,17 +442,22 @@ static int at25_probe(struct spi_device *spi) >> if (IS_ERR(at25->nvmem)) >> return PTR_ERR(at25->nvmem); >> >> - dev_info(&spi->dev, "%d %s %s eeprom%s, pagesize %u\n", >> + has_erase = (!(chip.flags & EE_READONLY) && at25->erase_instr); >> + >> + dev_info(&spi->dev, "%d %s %s eeprom%s, pagesize %u%s\n", >> (chip.byte_len < 1024) ? chip.byte_len : (chip.byte_len / 1024), >> (chip.byte_len < 1024) ? "Byte" : "KByte", >> at25->chip.name, >> (chip.flags & EE_READONLY) ? " (readonly)" : "", >> - at25->chip.page_size); >> + at25->chip.page_size, (has_erase)?" ":""); >> + >> + if (has_erase && device_create_file(&spi->dev, &dev_attr_erase)) >> + dev_err(&spi->dev, "can't create erase interface\n"); > You just raced with userspace and lost :( > > Please create an attribute group and add it to the .dev_groups pointer > in struct driver so it can be created properly in a race-free manner. > > See the thread at: > https://lore.kernel.org/r/20190731124349.4474-2-gregkh@linuxfoundation.org > for the details on how to do that. Clearly I didn't know about that. I'll do some reading when I've got a bit of time and try a again. > thanks, > > greg k-h Cheers, Joe