Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp280230ybl; Fri, 9 Aug 2019 06:01:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqwz20iz60LgbVE8fP8Td3iC4tqp62CYzoXDRvrkB532Pn69aTLQ+OW5ChT/oDc9zJ/j4r2N X-Received: by 2002:a17:902:9f81:: with SMTP id g1mr18655831plq.17.1565355671335; Fri, 09 Aug 2019 06:01:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565355671; cv=none; d=google.com; s=arc-20160816; b=l/mBGLKgXJ6Fnzqjjpc2sKvjHzl8+G+dXodEZhD8fYRCaKd5drgPWFvgNFlYd8uH4o sN0PAw/JF4A1IB6I9qV0Vpnw6yA326QRqjfhGVZuYfkr6r/B69N/UNJmUwVpFvykxTOl g6Nh01lzHRwZ4eUWsXjJUFYc3Db1uOiB3TsY8B/d4eCVikNR4/BQ94hz8na+VAWnlVoY sfA/7bO4ezZBkeClYj25V6+5YoibbzOqJS1t7Oxnw1hiPz69H4MjD4Q/qrxVrNp8G1Iq FVh7H8jWBEjyjOpSrdkLglJ9C7MCgXq/ZF/PUq4h2MMRUPW97rGE7QOFpiFapngx/+G8 DloQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=XWlbSjd7yqQCJyBoW3mJXsOu+zY1x+07rLRx13UKOTA=; b=SqNG/nfQZUJAsJueI577314zNNc58hbJMxSSr/zXYsUe29IscAi5wt/00Y8eogM/eL byMTesjLFMmPWmbJYvhn0BxlFOCNiAB8Y2k8b5gj9S4OwU2sCbyLW0svLKUirB3L0XYW x8OZOH3S1TcUrBdx0KYucj4ne4lqucVlmVwqr3+kY4hMiiuvUDm66PmMbfmQ6Lzl0Prn NOpUWEGMCjknMWEo9VwDEzoPCQZZBVkUYCaxPlnLWwG8yocwUq0mEHsTscX1jMwCzNUh uFRbpkLR7mMMxl3/k5QzjzAJEpymCkz3OG1zuJLAVnP84hE7q5jP8rlpzWLh8fQRqEHp 5H+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QZK6BTSH; 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 131si49845487pgf.597.2019.08.09.06.00.54; Fri, 09 Aug 2019 06:01:11 -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=@kernel.org header.s=default header.b=QZK6BTSH; 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 S2406954AbfHINAJ (ORCPT + 99 others); Fri, 9 Aug 2019 09:00:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:44930 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726157AbfHINAJ (ORCPT ); Fri, 9 Aug 2019 09:00:09 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2DCF020B7C; Fri, 9 Aug 2019 13:00:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565355607; bh=iDWm4tx1wC6eLb9RWMaVgsIMEJY2hF+w7j8VkSayoo8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=QZK6BTSHaAol78GPo+Y5GRnYjKPVwg3rODZUsyUhYlZ5M85m65KYBBe3xgYzevA81 BySmSkonFQQiLBQX4n7PX5CZHLSdLYqP8Oe6LWMTsSfFKgwWnLzjIIslNgKGVPNDOW nIpYL1s1RL1gPqpxZw0yCwtywrc+Vtx0Q8ocJiXY= Date: Fri, 9 Aug 2019 15:00:05 +0200 From: Greg Kroah-Hartman To: Joe Burmeister Cc: Rob Herring , Mark Rutland , Arnd Bergmann , Srinivas Kandagatla , YueHaibing , Bartosz Golaszewski , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] Add optional chip erase functionality to AT25 EEPROM driver. Message-ID: <20190809130005.GA13962@kroah.com> References: <20190809125358.24440-1-joe.burmeister@devtank.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190809125358.24440-1-joe.burmeister@devtank.co.uk> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 :( > +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? > 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. thanks, greg k-h