Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp5190610imm; Tue, 16 Oct 2018 06:37:42 -0700 (PDT) X-Google-Smtp-Source: ACcGV623ovmlwG9KY7s3+rVs4qmvlBayOXmUkXEwNs5u5ysZOpxq1BsFsofMos2K6zBzNQ+ldWAU X-Received: by 2002:a63:2066:: with SMTP id r38-v6mr20193987pgm.289.1539697062751; Tue, 16 Oct 2018 06:37:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539697062; cv=none; d=google.com; s=arc-20160816; b=XO6WpM0g5ctFInkHzOB7PURWEmhG71RdhUMJ3i6H3umKMmkTgmTrrRlsB/IztGC02s 2/ulYPPGXVHuLwSVrqNvQIkJ9qU2JmL8KKmBuWV/qdPi6f7FsaRmsmp6YNj6K9rGqhN+ OGLab5RxyxXCx7IXp4UZoVrbUeUN70bIWRgNbd1dP+BE6uIrwWeX6nnsleNRRS++D9mX IYUC5pQvTfWdSuu+ahVPNi49TIjTk0/evJ9t/3WN+be3eUugBuZ05kKC71Ix/VTlICnt 5tUy+VGDGzy2I0a3Si1KrPcQd3JqciNDO78jn44HAMGEzhoIDkHCuEFpWpAtDSeZVMut EiyA== 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=ilSKTIHNrFgTNNUmmNh0o6KWqQdusr0cIfTck96jS4g=; b=uwmww9qeXCJ/E9P29+5dbtdhhr7S5shYcXXul5eoMmg5WW6SIrj2Hjk7MCR+iO5l57 5sb+KQfqxMt8lwjJt1Fr0tq0jkPSDxZQw6XDN2124Oni8RQKSRJksCh+lvGdEgU0i5QF TgphllR9gTAOXyg76c+bPDXRPG+zN07xcqlhECr2IP5idyGrrplOVdWKfZqOECgshLvF JfAQVUFB6IZO3UZ5Obvx5NvkpiVj4LsfbZTXsL8fDAHi6+RTYsKudDkYwJ1SOdLT6ElQ Gx8HsIz+osbsIGq7pCL69h9dqGrV79tMUakrMzlb6ckmR/hVRfS9HrCB1zqMgNtqmk9g QRVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=i2ePuyZX; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e5-v6si8522664pfg.87.2018.10.16.06.37.26; Tue, 16 Oct 2018 06:37:42 -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=@gmail.com header.s=20161025 header.b=i2ePuyZX; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727174AbeJPVZ1 (ORCPT + 99 others); Tue, 16 Oct 2018 17:25:27 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:33408 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727003AbeJPVZ1 (ORCPT ); Tue, 16 Oct 2018 17:25:27 -0400 Received: by mail-lj1-f194.google.com with SMTP id z21-v6so20925359ljz.0 for ; Tue, 16 Oct 2018 06:34:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ilSKTIHNrFgTNNUmmNh0o6KWqQdusr0cIfTck96jS4g=; b=i2ePuyZX4B6qwbmkOD4uw+QJ5s7kdVP3ODm2AgaEtGSwPMsKz9OKTDgUvvo6JKQpNL GZgOs215jwl5ILcm4Fnx1dTeiSdaNhi12CsXvYuW59O8DTmmKSIF294Zd+gD6OTbf/9F texoWz+9a/2aDji2CiE7gGmtgV1zn2sA00WOP/3RsUN6TaV2dqAMlQixTyxG1j4LIL9z SzfEVJmrPD5gbWrEfDIvDFolh0O+uvviKzK6HO34Q+lx9mXkT7TgAjqhOORMp0MBnSDx pMF83ei+5Io8tVfHOS3D9lbkBbALJYc05MOxZVYKHhfgmeMfd0Hr9dWEOX2UN0tiQeBL sJ0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ilSKTIHNrFgTNNUmmNh0o6KWqQdusr0cIfTck96jS4g=; b=Rcb+zB9JDfhHeTJOhhSmgr1E21h45FWwsp7NFmvQ5LBSeBgJwcTTeJiMByIkXMhNWv c5w2VhpmI1R3MXA/EOsFfrnDp5HuQcC9TeK0pX+KXtqfuXWZhPb3CSdsEvw8vBO3g8y9 YIizBuvk+SIWawfsdPaBAHGiOekvfyDskaxol/UjFpqn/4Ge0Edw7O5jqoIgfe3uiUDv MEq05+Ng2nXJPmYjEtq33rOGpr7Vfi1owdoHthTJXW/L2QUaaWdSn8tJ/6l4GK9YQcJk mTXXwaMP7nrz6drOiNdVnmjQ0QLNr7H5VqQp/WZQQAsaM6KfwakTR+1noiQ0gRDKXSL8 M1Gg== X-Gm-Message-State: ABuFfoj+BqDQQVqMNl3T2slTCim+MFbul85xWoi3q4rAbi840Nfyjaf+ 9CdqL7pTKu6pn/Nt++lTPH4= X-Received: by 2002:a2e:9955:: with SMTP id r21-v6mr13263285ljj.5.1539696894036; Tue, 16 Oct 2018 06:34:54 -0700 (PDT) Received: from metis.ciupak.eu ([31.130.108.122]) by smtp.gmail.com with ESMTPSA id h8-v6sm2981999lfc.47.2018.10.16.06.34.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Oct 2018 06:34:53 -0700 (PDT) Date: Tue, 16 Oct 2018 17:39:15 +0200 From: Marcin Ciupak To: Dan Carpenter Cc: Greg Kroah-Hartman , Joe Perches , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] staging: add nrf24 driver Message-ID: <20181016153915.uknqmey6ko2ldnbw@metis.ciupak.eu> References: <20181016101747.ex6ftchhsiyzdjti@metis.ciupak.eu> <20181016114150.2acsbpluwqe6d4l3@mwanda> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181016114150.2acsbpluwqe6d4l3@mwanda> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 16, 2018 at 02:41:50PM +0300, Dan Carpenter wrote: > When we add drivers, can we use the new subsystem prefix for the driver? > In other words: > > [PATCH] staging: nrf24: Add new driver for 2.4Ghz radio transceiver > Sure. > This driver seems basically OK to me. I don't think you necessarily > need to go through staging? Have you tried sending it directly to > netdev? > I have not tried that, mainly as I believe it is not mature enough. I would give it some time in staging for testing and bugfixing. If you say that it is not needed and can be done out of staging, I will ask netdev if it can be accepted there. > > + //take out size of data > > This comment is sort of useless? "take out" is like Chinese food. It > seems like it should be obvious what the code does. The format is > wrong. So there are very minor things to be tidied up. > Agree, I will do comments cleanup. > > + ret = kfifo_out(&device->tx_fifo, &size, sizeof(size)); > > + if (ret != sizeof(size)) { > > + dev_dbg(&device->dev, "get size from fifo failed\n"); > > + mutex_unlock(&device->tx_fifo_mutex); > > + continue; > > + } > > + > > + //alloc space for data > > + buf = kzalloc(size, GFP_KERNEL); > > + if (!buf) { > > + dev_dbg(&device->dev, "buf alloc failed\n"); > > + mutex_unlock(&device->tx_fifo_mutex); > > + continue; > > + } > > + > > + //take out size of data > > + ret = kfifo_out(&device->tx_fifo, buf, size); > > + if (ret != size) { > > + dev_dbg(&device->dev, "get buf from fifo failed\n"); > > + mutex_unlock(&device->tx_fifo_mutex); > > + goto next; > > + } > > + > > + //unlock tx fifo > > + mutex_unlock(&device->tx_fifo_mutex); > > + > > + //enter Standby-I mode > > + nrf24_ce_lo(device); > > + > > + //set TX MODE > > + ret = nrf24_set_mode(device->spi, NRF24_MODE_TX); > > + if (ret < 0) > > + goto next; > > + > > + //set PIPE0 address > > + //this is needed to receive ACK > > + ret = nrf24_set_address(device->spi, > > + NRF24_PIPE0, > > + (u8 *)&p->cfg.address); > > + if (ret < 0) { > > + dev_dbg(&device->dev, "set PIPE0 address failed (%d)\n", ret); > > + goto next; > > + } > > + > > + //set TX address > > + ret = nrf24_set_address(device->spi, > > + NRF24_TX, > > + (u8 *)&p->cfg.address); > > + if (ret < 0) { > > + dev_dbg(&device->dev, "set TX address failed (%d)\n", ret); > > + goto next; > > + } > > + > > + //check if pipe uses static payload length > > + spl = p->cfg.plw != 0; > > + > > + //check if dynamic payload length is enabled > > + dpl = nrf24_get_dynamic_pl(device->spi); > > + > > + if (spl && dpl) { > > + //disable dynamic payload if pipe > > + //does not use dynamic payload > > + //and dynamic paload is enabled > > + ret = nrf24_disable_dynamic_pl(device->spi); > > + if (ret < 0) > > + goto next; > > + } > > + > > + memset(pload, 0, PLOAD_MAX); > > + memcpy(pload, &size, sizeof(size)); > > + > > + //calculate payload length > > + n = spl ? p->cfg.plw : sizeof(size); > > + > > + //send size > > + nrf24_write_tx_pload(device->spi, pload, n); > > + if (ret < 0) { > > + dev_dbg(&device->dev, "write TX PLOAD failed (%d)\n", ret); > > + goto next; > > + } > > + > > + //enter TX MODE and start transmission > > + nrf24_ce_hi(device); > > + > > + //wait for ACK > > + wait_event_interruptible(device->tx_done_wait_queue, > > + (device->tx_done || > > + kthread_should_stop())); > > + > > + if (kthread_should_stop()) > > + goto abort; > > + > > + //clear counter > > + sent = 0; > > + > > + while (size > 0) { > > + n = spl ? p->cfg.plw : min_t(ssize_t, size, PLOAD_MAX); > > + > > + dev_dbg(&device->dev, "tx %zd bytes\n", n); > > + > > + memset(pload, 0, PLOAD_MAX); > > + memcpy(pload, buf + sent, n); > > + > > + //write PLOAD to nRF FIFO > > + ret = nrf24_write_tx_pload(device->spi, pload, n); > > + > > + if (ret < 0) { > > + dev_dbg(&device->dev, > > + "write TX PLOAD failed (%d)\n", > > + ret); > > + goto next; > > + } > > + > > + sent += n; > > + size -= n; > > + > > + device->tx_done = false; > > + > > + //wait for ACK > > + wait_event_interruptible(device->tx_done_wait_queue, > > + (device->tx_done || > > + kthread_should_stop())); > > + > > + if (kthread_should_stop()) > > + goto abort; > > + } > > +next: > > + //free data buffer > > + kfree(buf); > > + > > + //restore dynamic payload feature > > + if (dpl) > > + nrf24_enable_dynamic_pl(device->spi); > > + > > + //if all sent enter RX MODE > > + if (kfifo_is_empty(&device->tx_fifo)) { > > + dev_dbg(&device->dev, "%s: NRF24_MODE_RX\n", __func__); > > + > > + //enter Standby-I > > + nrf24_ce_lo(device); > > + > > + p = nrf24_find_pipe_id(device, NRF24_PIPE0); > > + if (!IS_ERR(p)) { > > + //restore PIPE0 address > > + nrf24_set_address(device->spi, > > + p->id, > > + (u8 *)&p->cfg.address); > > + } > > + //set RX MODE > > + nrf24_set_mode(device->spi, NRF24_MODE_RX); > > + > > + //enter RX MODE and start receiving > > + nrf24_ce_hi(device); > > + } > > + } > > +abort: > > + kfree(buf); > > + > > + return 0; > > +} > > + > > [ snip ] > > > +static int nrf24_gpio_setup(struct nrf24_device *device) > > +{ > > + int ret; > > + > > + device->ce = gpiod_get(&device->spi->dev, "ce", 0); > > + > > + if (device->ce == ERR_PTR(-ENOENT)) > > + dev_dbg(&device->dev, "%s: no entry for CE\n", __func__); > > + else if (device->ce == ERR_PTR(-EBUSY)) > > + dev_dbg(&device->dev, "%s: CE is busy\n", __func__); > > + > > + if (IS_ERR(device->ce)) { > > + ret = PTR_ERR(device->ce); > > + dev_err(&device->dev, "%s: CE gpio setup error\n", __func__); > > + return ret; > > + } > > + > > + nrf24_ce_lo(device); > > + > > + //irq > > + ret = request_irq(device->spi->irq, > > + nrf24_isr, > > + 0, > > + dev_name(&device->dev), > > + device); > > + if (ret < 0) { > > + free_irq(device->spi->irq, device); > > I don't think we need to free this because the requiest failed. > True, free_irq is not needed here. > I'm not a huge fan of your label naming scheme. You're generally using > come-from names like "alloc_failed:" but that doesn't tell you what the > goto does so I have to open two windows and manually line up the gotos > with the labels to see what the goto does. It's better for the name > to say "err_put_ce". > I got your point and it make sens. I will review and try to rename labels accordingly. > > + goto err; > > + } > > + > > + return 0; > > + > > +err: > > + gpiod_put(device->ce); > > + return ret; > > +} > > + > > +static void nrf24_dev_release(struct device *dev) > > +{ > > + struct nrf24_device *device = to_nrf24_device(dev); > > + > > + ida_simple_remove(&nrf24_ida_dev, device->id); > > + kfree(device); > > +} > > + > > +static struct device_type nrf24_dev_type = { > > + .name = "nrf24_device", > > + .release = nrf24_dev_release, > > +}; > > + > > +static struct nrf24_device *nrf24_dev_init(struct spi_device *spi) > > +{ > > + int ret; > > + struct nrf24_device *device; > > + int id; > > + > > + id = ida_simple_get(&nrf24_ida_dev, 0, 0, GFP_KERNEL); > > + if (id < 0) > > + return ERR_PTR(id); > > + > > + //sets flags to false as well > > + device = kzalloc(sizeof(*device), GFP_KERNEL); > > + if (!device) { > > + ida_simple_remove(&nrf24_ida_dev, id); > > + return ERR_PTR(-ENOMEM); > > + } > > + device->spi = spi; > > + > > + dev_set_name(&device->dev, "nrf%d", id); > > + device->id = id; > > + device->dev.parent = &spi->dev; > > + device->dev.class = nrf24_class; > > + device->dev.type = &nrf24_dev_type; > > + device->dev.groups = nrf24_groups; > > + ret = device_register(&device->dev); > > + if (ret < 0) { > > + put_device(&device->dev); > > We don't have to do ida_simple_remove()? > We do have to do ida_simple_remove. I missed it! > > + return ERR_PTR(ret); > > + } > > + > > + init_waitqueue_head(&device->tx_wait_queue); > > + init_waitqueue_head(&device->tx_done_wait_queue); > > + init_waitqueue_head(&device->rx_wait_queue); > > + > > + INIT_WORK(&device->isr_work, nrf24_isr_work_handler); > > + INIT_KFIFO(device->tx_fifo); > > + spin_lock_init(&device->lock); > > + mutex_init(&device->tx_fifo_mutex); > > + > > + INIT_LIST_HEAD(&device->pipes); > > + > > + return device; > > +} > > [ snip ] > > > +static ssize_t address_show(struct device *dev, > > + struct device_attribute *attr, > > + char *buf) > > +{ > > + struct nrf24_device *device = to_nrf24_device(dev->parent); > > + u8 addr[16]; > > + int ret; > > + int count; > > + int i; > > + struct nrf24_pipe *pipe; > > + > > + pipe = nrf24_find_pipe_ptr(dev); > > + if (IS_ERR(pipe)) > > + return PTR_ERR(pipe); > > + > > + ret = nrf24_get_address(device->spi, pipe->id, addr); > > + if (ret < 0) > > + return ret; > > + > > + count = snprintf(buf, PAGE_SIZE, "0x"); > > + for (i = --ret; i >= 0; i--) > > + count += snprintf(buf + count, PAGE_SIZE, "%02X", addr[i]); > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > > + count += snprintf(buf + count, PAGE_SIZE, "\n"); > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > > This isn't right. Use scnprintf(). The snprintf() function returns > the nubmer of characters that would have been written if we had space. > And it should be PAGE_SIZE - count. > You are right, I will use scnprintf here. > > + > > + return count; > > +} > > + > > > regards, > dan carpenter Thanks for the review, I will send v3 in some time now. br, Marcin