Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1635112imm; Sun, 23 Sep 2018 08:17:54 -0700 (PDT) X-Google-Smtp-Source: ACcGV61/usVyL+HRNGs2CifzwiMw0QHutERKFrCk9Fw7oJHqD3Wd5wsVvg39zrd+DISWCC/0ce6f X-Received: by 2002:a17:902:6a:: with SMTP id 97-v6mr6887998pla.276.1537715874265; Sun, 23 Sep 2018 08:17:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537715874; cv=none; d=google.com; s=arc-20160816; b=boj0cBTx2gch9lf1PaS7n0vZ2JAcGlpc/DW5CAD63eGbW3tgZbuM1o4cKVVQzVUfI7 L6vOpM15K2s631M8Y02AMv2c8WpW4WGt3OPfOdujsXibgFb45UQ6ofwg1iwNlRCzmXIQ oF/Ku7epfc/GU2niLi362h6wUDCDDLHY5njvQ/940N/OGV82kVotIueIf6Z9DFlVrwTA 9GDro9JEvG65FHHWkkTqbf6uswe1AjuOg7gWe/my3n1XtioHqYxk0SzPzdnyVtw8H7I6 UgTqm3KnNoQPD/CSKMQrcqmlLrQyRoAJO3lbhJK9yq5EojOqeXP1cU26mDYN6mkxauxr mDzQ== 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=XKCYq1sfWZ0J4ewDvnSWD0Bw2XVndWgA64gp6BPgE/I=; b=V4h7BMaDDnf6uH+X1H1dl8Kh9LaMvoadERHQTg1DdyH0Be3ZBXUgY4+BkW80d6lbg7 hRjdpYOuizlHT0XZl4duO9Vee6R6AFklwFcL75tWJ4M0KA5ryiaN98Rp0v4RaCNxKBt1 JQy/G3zshpuyKKXexgjv6CrDtlsqwj5nLbC8agt0tO0ujbFZnad9DDArLtnudNP2NAyE 83OqWqzsY2c7R3F/Wko3bxs5eL/d5dF32YYfpIAaUN0WBuLHDVCNRIURCJTxecXcKJ3O NfCpF1sxfeiaj8NzQfikbP3ZsNPOfDLJhOn36cYho7kwBHEftgA96lk3SowLXqKfdMxJ B3Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fhvwwbqh; 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 l26-v6si5866348pgb.251.2018.09.23.08.17.37; Sun, 23 Sep 2018 08:17:54 -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=fhvwwbqh; 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 S1726269AbeIWVPV (ORCPT + 99 others); Sun, 23 Sep 2018 17:15:21 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:46354 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726168AbeIWVPV (ORCPT ); Sun, 23 Sep 2018 17:15:21 -0400 Received: by mail-pl1-f196.google.com with SMTP id v19-v6so345910ply.13; Sun, 23 Sep 2018 08:17:32 -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=XKCYq1sfWZ0J4ewDvnSWD0Bw2XVndWgA64gp6BPgE/I=; b=fhvwwbqhqb4ENTlnWyozoleNehq+JV8ReZNYf98GyEZPXZ0mpE6PfciBE9Y151Chcz sA4b0PYy6wS8HAuXk7VIhVpxvPmozj4/xzazY5g8EnEEMnWHWaLpQjUYQCbV9fzpIv4N nF+vEWT2aPC75Sp3vsf5WT/qM+8LNyqkkAfC9rZHLg5LfD2GoYKlkIGeliyHAk2B107A Fffn9M4BAJH1nHs3HubK6Zmf7EAa86sQkL1WhNXWQNYzbQN6zRQArYhSmfvqVM4pv7xk LRbPcF7BwRwqwzNbdoymoEWM0kWFHbXegCWUJgMgPKpeiU3da6195lLzBje6RKkZ+SmP BJoQ== 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=XKCYq1sfWZ0J4ewDvnSWD0Bw2XVndWgA64gp6BPgE/I=; b=JK9hrbCwlyCNcvge8o98GwfEQ0yigtnN58NP7yyS3lw6k2FktGvovbqksBmf5sZbUK B18zc5gwKSh3g9iX6vBgMsrfajkq4jKFW2NJAs3iXPxO7mx00R+3paJQI4DdlQHpoMvs qI1RdvHyoDl7/lyvXLFSuyUIm+3NtkZHfXYBGoMoNflmwyfHPLw/fvsa8zIccz0tUrWc DvXJ8HnoPJD/l8jE2AW4VXEVbknfLGeVlkSK8V7B3uG6Pdi7cizvFez5RTrxvaPQPUBA N/9YF+sbnFgOtK2fisIUX2U5uNewkjDFjrArYF5mlR0al0OudF9UrSaEtq9xp2HK6Nmy Oh3A== X-Gm-Message-State: ABuFfohlSoQQSKNhKB+ZOnCbpM5g0JmKjOA0j2XlHz4JhMpRqhpUhQvb o64BNI0TM8iezUs6J2YX100= X-Received: by 2002:a17:902:34a:: with SMTP id 68-v6mr7028448pld.39.1537715852429; Sun, 23 Sep 2018 08:17:32 -0700 (PDT) Received: from Eros (104.176.229.35.bc.googleusercontent.com. [35.229.176.104]) by smtp.gmail.com with ESMTPSA id p75-v6sm3028628pfi.22.2018.09.23.08.17.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 23 Sep 2018 08:17:31 -0700 (PDT) Date: Sun, 23 Sep 2018 23:17:22 +0800 From: Song Qiang To: Jonathan Cameron Cc: knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, robh+dt@kernel.org, mark.rutland@arm.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] iio: magnetometer: Add support for PNI RM3100 9-axis magnetometer Message-ID: <20180923151722.GA17711@Eros> References: <20180920131340.6699-1-songqiang1304521@gmail.com> <20180922111409.597126fd@archlinux> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180922111409.597126fd@archlinux> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Sep 22, 2018 at 11:14:09AM +0100, Jonathan Cameron wrote: > On Thu, 20 Sep 2018 21:13:40 +0800 > Song Qiang wrote: > ... > > +const struct regmap_access_table rm3100_volatile_table = { > > + .yes_ranges = rm3100_volatile_ranges, > > + .n_yes_ranges = ARRAY_SIZE(rm3100_volatile_ranges), > > +}; > > + > > +static irqreturn_t rm3100_measurement_irq_handler(int irq, void *d) > > Silly question: Does the chip have two interrupt lines? (if so they > should be in the binding). If not, then this is the irq handler > for everything so why have the measurement in it's name? > Hi Jonathan Ah, always some other things need to care, I didn't put enough focus on this naming and thought it looks like ok. So I should throw these unnecessary information in names away! > > +{ > > + struct rm3100_data *data = d; > > + > > + complete(&data->measuring_done); > > + > > + return IRQ_HANDLED; > > +} ... > > + if (ret < 0) > > + return ret; > > + > > + /* 3sec more wait time. */ > > + ret = regmap_read(data->regmap, RM_REG_TMRC, &tmp); > > + data->conversion_time = rm3100_samp_rates[tmp-RM_TMRC_OFFSET][2] + 3000; > > + > > + /* Starting all channels' conversion. */ > > + ret = regmap_write(regmap, RM_REG_CMM, > > + RM_CMM_PMX | RM_CMM_PMY | RM_CMM_PMZ | RM_CMM_START); > > + if (ret < 0) > > + return ret; > > + > > + return devm_iio_device_register(dev, indio_dev); > Nope. Can't do this without having a race condition. You need > to ensure the userspace and in kernel interfaces are removed 'before'. > you do that RM_REG_CMM write in remove. > > One option is to use devm_add_action to add a custom unwind function > to the automatic handling. The other is to not use devm for everything > after the write above and do the device_unregister manually. > I've already handled some of those problems, and most of them are not a big deal, except this one and the locking problems, about how should I deal with locks properly. I'm already reading the lockdep conventions and some articles about it. Autobuilder are complaining about my locks, seems like a mess it is! > > +} > > +EXPORT_SYMBOL(rm3100_common_probe); > > + > > +int rm3100_common_remove(struct device *dev) > > +{ > > + struct iio_dev *indio_dev = dev_get_drvdata(dev); > > + struct rm3100_data *data = iio_priv(indio_dev); > > + struct regmap *regmap = data->regmap; > > + > > + regmap_write(regmap, RM_REG_CMM, 0x00); > > + > > + return 0; > No real point in returning int if you are always going to put 0 in > in it. Should probably check the regmap_write though and output > a log message if it fails (as no other way of telling). > > > +} > > +EXPORT_SYMBOL(rm3100_common_remove); > > + ... > > +struct rm3100_data { > > + struct device *dev; > > + struct regmap *regmap; > > + struct completion measuring_done; > > + bool use_interrupt; > > + > > + int conversion_time; > > + > > + /* To protect consistency of every measurement and sampling > > /* > * To protect > */ > (common format to most of the kernel other than those 'crazy' :) > people in net and a few other corners. > Actually, I've been wondering why the perl scripts didn't find this out, and not only this one, many other problems like too many indents, parameters in open brackets are not aligned can be detected. I don't know perl, but this has drawn my attention. Is there any particular reason these problems still can not be detected? or I think we can work some patch out! Make reviewing code like mine easier! yours, Song Qiang > > + * frequency change operations. > > + */ > > + struct mutex lock; > > +}; > > + > > +extern const struct regmap_access_table rm3100_readable_table; > > +extern const struct regmap_access_table rm3100_writable_table; > > +extern const struct regmap_access_table rm3100_volatile_table; > > + > > +int rm3100_common_probe(struct device *dev, struct regmap *regmap, int irq); > > +int rm3100_common_remove(struct device *dev); > > + > > +#endif /* RM3100_CORE_H */ >