Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp3774069ybh; Tue, 6 Aug 2019 01:05:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqyyQV07DAbwyf2KbWRIHAVUx8BGfvBf0Wc01Y9DI5RW690jmGrlc9pQjEcR8S7vyqHPyUi/ X-Received: by 2002:a65:6497:: with SMTP id e23mr1822892pgv.89.1565078712158; Tue, 06 Aug 2019 01:05:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565078712; cv=none; d=google.com; s=arc-20160816; b=xndKm2oAk4RtXAn7LU9msk6JTxz6VoN3Yds+2wGdt1tVFh56vejLl5fSmS8SeWg2/3 95yuLMV03vGikG1zuPiYHe08hNNunTpdGgdZBAljQQGjhiUlde5C+X6KmGwSKqh9APZL 0O/zY5YWLqaFlvYfT4Lby1B0QxSbme648xDAPLeopVGvAU5te8J6OCqrvTcyHm8BAYkx obqsC/c+2MHzGjYPAKX2652CjBQ2q0jGddXIG4x8ct33OtXbUBVhf/N2flSASSaGBp9O s1dRBxj7QcrGg1auzXNkzC/XiyupLX156ests/vRvXK4nY64AuMxWUTsOPs0AU5ca7ZX T1lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:subject:message-id:date:from:reply-to :in-reply-to:references:mime-version; bh=M6h+ZLVGP5Nx+kft/9Cf+xMsyHHRiA7dp9KBoAgSGBE=; b=j6AMIwQYD3WSqa6RcuX7XKrltk4FDIyipPFNAOCQKuz/WiOW1wQl/Y6Bez+4Z2lfmj bMDlF2480TbALJmoFZEXg2ws0nQ4Y9BMISEcNcqgS3bObB7g9HVWrIgvEHzOp44hhLhs rthnWcD9jqjwX7y8jLgMZppaAZXVXw2b+urnYmOk+DJHJ0qSwny3ewxstRalGNKTzgn6 MEzGN3ILXsa7Y2U9YpNast8felTt8IvxS2qdeR8QkLjntvSgy0E4kyC9lMJHrqyfTTFN 91umZV6nNlUcaBYz90N+L97gVtPF598r9Pthv4lPd+LAL3LN+KK1KqUIjXYfyj4yLPjP No2w== ARC-Authentication-Results: i=1; mx.google.com; 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 m15si50314924pgt.495.2019.08.06.01.04.56; Tue, 06 Aug 2019 01:05:12 -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; 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 S1732229AbfHFIC6 (ORCPT + 99 others); Tue, 6 Aug 2019 04:02:58 -0400 Received: from mail-vs1-f49.google.com ([209.85.217.49]:43737 "EHLO mail-vs1-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732122AbfHFIC5 (ORCPT ); Tue, 6 Aug 2019 04:02:57 -0400 Received: by mail-vs1-f49.google.com with SMTP id j26so57755934vsn.10 for ; Tue, 06 Aug 2019 01:02:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:reply-to :from:date:message-id:subject:to; bh=M6h+ZLVGP5Nx+kft/9Cf+xMsyHHRiA7dp9KBoAgSGBE=; b=DgBSZCyu4R6atU1vUD8Ya3ipPUML7pl3gQqYktueClFmlo3hBFxCY8C7uFfG3AbhOt KnUWVrmz4FKW+vfR2OCdKt9uXB/9MV6ZoP8p+/OWplvN0UwVb4HD0eFgGdLDOugPXayQ FQ2AjMEO4ou1uoJ/wkhoMSUfQZ2d4S7Iv+NOrdXL99kHwV653ezTzoXQxPjQPuCJJizI RSiOuAWcRdZ/8Zl4xy5N11ex8daPcsm2sdOuo75qXP+tOmKR8WYqM4U4MzR/P+dpFNGB qQIWPVcYMg5gv15ClBjFI2n37sk3DSoQTrJdMNHELjz0bvNnEKboPJvtgNYADKHxUZIE 5PVw== X-Gm-Message-State: APjAAAUiZolOgZOfTx8qdiVzxjoYhwp4gJiTxr+bJI1vZ7Yx/DS0t+Ey Fqvf1/5Do9sRcBCzKIpCYaSvBZbcpJo= X-Received: by 2002:a67:ed81:: with SMTP id d1mr1457402vsp.157.1565078576647; Tue, 06 Aug 2019 01:02:56 -0700 (PDT) Received: from mail-vs1-f45.google.com (mail-vs1-f45.google.com. [209.85.217.45]) by smtp.gmail.com with ESMTPSA id j80sm17911531vkj.47.2019.08.06.01.02.56 for (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Tue, 06 Aug 2019 01:02:56 -0700 (PDT) Received: by mail-vs1-f45.google.com with SMTP id h28so57716862vsl.12 for ; Tue, 06 Aug 2019 01:02:56 -0700 (PDT) X-Received: by 2002:a67:f795:: with SMTP id j21mr1395756vso.226.1565078576215; Tue, 06 Aug 2019 01:02:56 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Reply-To: tanure@linux.com From: Lucas Tanure Date: Tue, 6 Aug 2019 09:02:45 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Question about mfd_add_devices and platform_data To: linux-kernel@vger.kernel.org, Lee Jones Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Lee, Can you help me with this question? Thanks Lucas On Mon, Aug 5, 2019 at 2:43 PM Lucas Tanure wrote: > > Hi, > > I would like to understand mfd_add_devices call and platform_data section. > An mfd device can have platform_data, which is kmemdup at > platform_device_add_data from platform_device_add_data call inside > mfd_add_device. And after this kmemdup the new mfd device receives the > clone memory and the pointer given to platform_device_add_data is freed. > > All the drivers I read the platform_data is static, which in my view can > not be freed and kfrees says: > > "Don't free memory not originally allocated by kmalloc() or you will run > into trouble." > > So, my questions is : Should my driver kmalloc platform_data first and then > call mfd_add_devices ? Or it's fine to give static memory to it ? > > Example driver: > > drivers/mfd/vexpress-sysreg.c: > > static struct syscon_platform_data vexpress_sysreg_sys_id_pdata = { > .label = "sys_id", > }; > > static struct mfd_cell vexpress_sysreg_cells[] = { > { > .name = "syscon", > .num_resources = 1, > .resources = (struct resource []) { > DEFINE_RES_MEM(SYS_ID, 0x4), > }, > .platform_data = &vexpress_sysreg_sys_id_pdata, > .pdata_size = sizeof(vexpress_sysreg_sys_id_pdata), > }, > > For this case mfd_add_devices will free vexpress_sysreg_sys_id_pdata, but > it's static. > > Thanks > Lucas