Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752745AbbFNTxQ (ORCPT ); Sun, 14 Jun 2015 15:53:16 -0400 Received: from isilmar-3.linta.de ([188.40.101.200]:36801 "EHLO linta.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751456AbbFNTw6 (ORCPT ); Sun, 14 Jun 2015 15:52:58 -0400 Date: Sun, 14 Jun 2015 21:52:46 +0200 From: Dominik Brodowski To: Alan Cox Cc: linux-kernel@vger.kernel.org, linux-pcmica@lists.infradead.org Subject: Re: [PATCH 4/5] pcmcia: handle anonymous cards by generating a fake CIS Message-ID: <20150614195246.GA13314@light.dominikbrodowski.net> References: <20141204212746.1351.89165.stgit@localhost.localdomain> <20141204213015.1351.23846.stgit@localhost.localdomain> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="k+w/mQv8wyuph6w0" Content-Disposition: inline In-Reply-To: <20141204213015.1351.23846.stgit@localhost.localdomain> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5663 Lines: 155 --k+w/mQv8wyuph6w0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Dec 04, 2014 at 09:30:56PM +0000, Alan Cox wrote: > The core pcmcia code blows up all over the place if it allowed a card wit= hout > a valid CIS. We need to allow such cards as the CIS stuff is not on the o= lder > flash, ROM and SRAM cards. We give it a suitably blank fake CIS instead. >=20 > In order to minimise the risk of misidentifying junk and feeding it to the > wrong thing we only fix up apparently anonymous cards if the driver for t= hem > has been enabled. Unfortunately, this patch does not work well with all of the callers of pccard_validate_cis(). While it helps for ds.c:pcmcia_card_add() and does not matter for cistpl.c:pccard_show_cis(), it breaks the callback in rsrc_nonstatic.c:readable(): There, we test whether iomem resources actually work -- and we test this by reading the CIS. This patch means that non-working resources are assumed to work -- and the valid CIS is replaced with the fake CIS in this case. Therefore, I'd suggest to move the override to the one place where it is needed -- to ds.c:pcmcia_card_add(). A patch which implements this is below; it fixes my test setup (which needs rsrc_nonstatic.c). Alan, could you verify this patch helps with the use case you had in mind when writing this patch? I inted to apply this patch to the PCMCIA tree only after such testing. Best, Dominik --------------------------------8<--------------------------------- pcmcia: do not break rsrc_nonstatic when handling anonymous cards Patch 1c6c9b1d9d25 caused a regression for rsrc_nonstatic: It relies on pccard_validate_cis() to determine whether an iomem resource can be used for PCMCIA cards. This override, however, lead invalid iomem resources to be accepted -- and lead to a fake CIS being used instead of the original CIS. To fix this issue, move the override for anonymous cards to the one place where it is needed -- when adding a PCMCIA device. CC: # for v4.0 and v4.1 Signed-off-by: Dominik Brodowski diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c index 64d0515..d444415 100644 --- a/drivers/pcmcia/cistpl.c +++ b/drivers/pcmcia/cistpl.c @@ -1451,26 +1451,16 @@ int pccard_validate_cis(struct pcmcia_socket *s, un= signed int *info) done: /* invalidate CIS cache on failure */ if (!dev_ok || !ident_ok || !count) { -#if defined(CONFIG_MTD_PCMCIA_ANONYMOUS) - /* Set up as an anonymous card. If we don't have anonymous - memory support then just error the card as there is no - point trying to second guess. - - Note: some cards have just a device entry, it may be - worth extending support to cover these in future */ - if (!dev_ok || !ident_ok) { - dev_info(&s->dev, "no CIS, assuming an anonymous memory card.\n"); - pcmcia_replace_cis(s, "\xFF", 1); - count =3D 1; - ret =3D 0; - } else -#endif - { - mutex_lock(&s->ops_mutex); - destroy_cis_cache(s); - mutex_unlock(&s->ops_mutex); + mutex_lock(&s->ops_mutex); + destroy_cis_cache(s); + mutex_unlock(&s->ops_mutex); + /* We differentiate between dev_ok, ident_ok and count + failures to allow for an override for anonymous cards + in ds.c */ + if (!dev_ok || !ident_ok) ret =3D -EIO; - } + else + ret =3D -EFAULT; } =20 if (info) diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index d3baf0b..e1498a0 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -634,8 +634,24 @@ static int pcmcia_card_add(struct pcmcia_socket *s) =20 ret =3D pccard_validate_cis(s, &no_chains); if (ret || !no_chains) { - dev_dbg(&s->dev, "invalid CIS or invalid resources\n"); - return -ENODEV; +#if defined(CONFIG_MTD_PCMCIA_ANONYMOUS) + /* Set up as an anonymous card. If we don't have anonymous + memory support then just error the card as there is no + point trying to second guess. + + Note: some cards have just a device entry, it may be + worth extending support to cover these in future */ + if (ret =3D=3D -EIO) { + dev_info(&s->dev, "no CIS, assuming an anonymous memory card.\n"); + pcmcia_replace_cis(s, "\xFF", 1); + no_chains =3D 1; + ret =3D 0; + } else +#endif + { + dev_dbg(&s->dev, "invalid CIS or invalid resources\n"); + return -ENODEV; + } } =20 if (!pccard_read_tuple(s, BIND_FN_ALL, CISTPL_LONGLINK_MFC, &mfc)) --k+w/mQv8wyuph6w0 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJVfduOAAoJEJqXYIlMjaMNTLMP/jlOgVx7TMNyLS63gLFM8yL3 boefWFYYUWUkeGyBnX6cP1/JsfoQ0RGoaM1jAL+0GWD3pDZW0/GZXAw6w3Is3wef sHzyimsfwAys5NGNASYDMgi/ken6kkKK0OwicO4qu4oNmhGKuaoYNTsDPJ7UT04I H7ZbGD+V7EbeC/3iGXAbLA/awXP/NDapsqRGkNNCB3az24knWiKe3JBPEfvwCLAN fvre6x3g+UhviGW8vnutDz0Ux0/JN4cvhEfWa1RqUAt6nHzNRyPJNiwJ9GfQqjR/ 1z3auGOaWgTkQqiy/eQDBLo16hNPb0BG7KhjJmKuXVgrmBSdq1B7xqhb+HTvZcyn Tz+w9RfAaweyMBrljikt7Ign24ZdR4cssH8CxN2mDQbMsbjeDORF9UqqAA1x/GY0 JypiXFWQIusJfePbLydwt1dwyFOQ+uVewTbo8a1Fh/ZJONJWbLuUTfDFxkpfJIZl FPi5WJD2pqKqozPcJR4B20WzDWWuZlvsoyH5DhyJ/joKEFvjNrYo8SFHyJ9IO7oE 60ffye8cYkS9iUJ0adZOMVD8J1tpWRd819gPfcGM9z/fVd7D0RyekdOIod2fqmoW 9wKP9FQgd6d+PimsCufrhpBNE68/sw+Kjd7ecrg7vHPg/e0kAWim9PoICUEr3pX+ JmB6kopCYqfRvDFPsWSf =Q1Ag -----END PGP SIGNATURE----- --k+w/mQv8wyuph6w0-- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/